1. Convert from basic data type to string
The string type provides the static method to convert the basic data type to the string type.
That is, the multiload method of the string. valueof () parameter.
There are several
String. valueof (Boolean B): Convert Boolean variable B to a string
String. valueof (char C): Convert char variable C to string
String. valueof (char [] data): converts the char array data to a string.
String. valueof (char [] data, int offset, int count ):
Convert count elements from data [offset] In char array data into strings
String. valueof (double D): Convert double variable d to string
String. valueof (float F): converts the float variable F to a string.
String. valueof (int I): converts int variable I to a string
String. valueof (long l): converts long variable L to a string
String. valueof (Object OBJ): converts an OBJ object to a string, which is equal to OBJ. tostring ()
Usage example:
Int I = 10;
String STR = string. valueof (I );
At this time, STR will be "10"
2. Convert string to the basic data type of a number
Convert string to basic data type
Most of the packages that require basic data types
For example, convert string to byte
You can use byte. parsebyte (string S)
If this method cannot analyze s, numberformatexception is thrown.
Byte:
Byte. parsebyte (string S): converts s to byte
Byte. parsebyte (string S, int Radix): converts s to byte Based on Radix.
For example, byte. parsebyte ("11", 16) will get 17
Double:
Double. parsedouble (string S): Convert s to double
Float:
Double. parsefloat (string S): converts s to float
INT:
Integer. parseint (string S): converts s to int
Long:
Long. parselong (string