The Integer class in java.lang calls its class method public static int parser (strings) to convert a string composed of "number" characters (such as "876") into an int data type, for example:
int x;
String s = " 876
x = integer . parse int(s);
Similarly, use the Byte, Short, Long, Float and Double classes in the java.lang package to call the corresponding class methods.
The public static byte parseByte (string s) throws NumberFormatException.
Public static short parseShort(String s) throws NumberFormatException.
The public static long parseLong (string s) throws NumberFormatException.
Public static double parseDouble(String s) throws NumberFormatException.
2. You can use the following methods to convert numbers into corresponding string objects:
① the value of the method
The public static string value of (byte n)
Common static string value Of(int n)
Public static string value Of(long n)
The public static string value of (floating point number n)
The public static string value of (double n)
For example, 123, 12345.8 and other numerical values are converted into strings.
string str = string . value of( 123)
string str = string . value of( 12345.8)
(2) You can use the toString method (an object can get the string representation of the object by calling this method).
Use the Byte, Integer, Short, Long, Float and Double classes in the java.lang package to call the corresponding class methods, such as Integer.toString, Double.toString and so on.
You usually use Integer.toString ("number to be converted"), which gets a String object.
Example:
int n = 123;
string m = integer . tostring(n);
system . out . println(m+ 1);
Date Date = new Date();
system . out . println(date . tostring());
So we can use the above method to convert numbers into strings.
3. Strings and character arrays
① Convert a character array into a string object
Use the construction methods of String class: string (char a []) and String(char a[], int offset, int length).
Construct string objects with all characters and some characters in array a respectively.
Example:
char a[] = {' 1 ',' 2 ',' 3 ' };
System.out.println (new string (a)). length());