Cheap VPS host selection
Provide server host evaluation information

The Method of Conversion from Integer to String in Java

Here we need to use integer to string to simply sort out several online conversion methods.

1、 Integer to String

Method 1: static method toString() of Integer class

Integer a = 2;
String str = Integer.toString(a)

Method 2: ToString(), a member method of Integer class

Integer a = 2;
String str = a.toString();

Method 3: static method valueOf() of String class

Integer a = 2;
String str = String.valueOf(a);

2、 String to Integer

 //When we want to convert a String to an Integer, we must make a non null judgment on the String, otherwise null pointer exceptions are likely to be reported. String str = "123"; Integer i = null; if(str!= null){ i = Integer.valueOf(str); }

 

Do not reprint without permission: Cheap VPS evaluation » The Method of Conversion from Integer to String in Java