1. The string type is converted from the basic information category.
The static method for converting basic data types into strings is provided in the string type.
That is, the method of string. valueof ().
There are the following types
String. valueof (Boolean B): converts Boolean to B into a string.
String. valueof (char C): converts a char to a string.
String. valueof (char [] data): Convert the data of the char character column into a string
String. valueof (char [] data, int offset, int count ):
Starting from data [offset] In the char primary column data, take count elements into strings.
String. valueof (double D): converts double into a string.
String. valueof (float F): converts a float value to a string.
String. valueof (int I): converts int into a string.
String. valueof (long l): converts long numbers into strings.
String. valueof (Object OBJ): convert an OBJ object into a string, such as obj. tostring ()
Usage example:
Int I = 10;
String STR = string. valueof (I );
At this time, STR will be "10"
2. Basic data types converted from string indexes to numbers
To convert string indexes into basic information indexes
Most package Types that require basic information
For example, string bytes are converted into bytes.
You can use byte. parsebyte (string S)
If this method cannot analyze s, numberformatexception will occur.
Byte:
Byte. parsebyte (string S): Convert s bytes to byte
Byte. parsebyte (string S, int Radix): Base Radix to convert s bytes to byte
For example, byte. parsebyte ("11", 16) will get 17
Double:
Double. parsedouble (string S): Convert s into double
Float:
Double. parsefloat (string S): Convert s into float
INT:
Integer. parseint (string S): Convert s into int
Long:
Long. parselong (string S): Convert s into long
Usage example:
try
{
String str = "1234";
int a = Integer.parseInt(str);
}
catch (NumberFormatException e)
{
System.out.println(" parse int error!! " + e);
}