Common string and character operations in Java (hexadecimal conversion, size conversion, data type conversion)

1. Convert java decimal numbers to hexadecimal

String hex= Integer.toHexString(numb);

2. Convert java hexadecimal characters to decimal numbers

BigInteger bigint=new BigInteger(hexs, 16);
int numb=bigint.intValue();

example:

import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        Scanner inp = new Scanner(System.in);
        int data = inp.nextInt();
        System.out.print(Integer.toHexString(data).toUpperCase());
    }
}


3. How to convert int to String in Java

1. There are two ways to convert String to int.

(1)Integer.parseInt(str)
(2)Integer.valueOf(str).intValue()

2. There are three ways to convert int to String

(1)num + “”
(2)String.valueOf(num)
(3)Integer.toString(num)

Using the first method is more time-consuming than the second and third methods

4.Java string uppercase to lowercase, lowercase to uppercase

String a = "ABC";
system.out.println(a.toLowerCase());//abc
String b = "abc";
system.out.println(b.toUpperCase());//ABC


————————————————
Original link: https://blog.csdn.net/m0_49936845/article/details/121604285

Guess you like

Origin blog.csdn.net/weixin_42602900/article/details/132881174