The Integer class in the java.lang package calls its class method public static int parseInt(String s) to convert a string composed of "numeric" characters, such as 123, into int type data, for example:
intx;Strings=123;x=Integer.parseInt(s);
In addition, you can also use the Byte, Short, Long, Float, and Double classes in the java.lang package to call the corresponding class methods, for example:
publicstaticbyteparseByte(Strings)throwsNumberFormatExceptionpublicstaticshortparseShort(Strings)throwsNumberFormatExceptionpublicstaticlongparseLong(Strings)throwsNumberFormatExceptionpublicstaticfloatparseFloat(Strings)throwsNumberFormatExceptionpublicstaticdoubleparseDouble(Strings)throwsNumberFormatException
Through the above method, we can convert a string composed of "numeric" characters into the corresponding basic data type.
Of course, we can also use the following class methods of the String class:
publicstaticStringvalueOf(byte)publicstaticStringvalueOf(intn)publicstaticStringvalueOf(shortn)publicstaticStringvalueOf(longn)publicstaticStringvalueOf(floatn)publicstaticStringvalueOf(doublen)
Convert a numeric value to a string, for example:
Stringstr=String.valueOf(123);