1. Conversion from basic data type to String
The static method for converting basic data types to string has been provided in the string category
That is, the string.valueof () is a method of multi-load parameter
Have the following types of
String.valueof (Boolean B): Converts a Boolean variable B to a string
String.valueof (char c): convert char variable C to string
String.valueof (char[] data): Converting char array data to a string
String.valueof (char[] data, int offset, int count):
Converts the char array data from Data[offset] to count elements to a string
String.valueof (double D): Converts a double variable d to a string
String.valueof (float f): Convert float variable F to string
string.valueof (int i): convert int variable i to string
String.valueof (Long L): convert long variable L to string
String.valueof (Object obj): Converts the Obj object to a string, equal to Obj.tostring ()
Usage such as:
int i = 10;
String str = string.valueof (i);
This time, STR will be "10."
2. Basic data type converted from String to digital
To convert a String to the basic data type, go
Most of the packaging categories that need to use basic data types
such as String conversion to byte
You can use Byte.parsebyte (String s)
This type of method will be thrown out if s analysis is not possible numberformatexception
BYTE:
Byte.parsebyte (String s): convert S to byte
Byte.parsebyte (String s, int radix): Converts S to byte with Radix as base
Say Byte.parsebyte ("11", 16) will get 17
Double:
Double.parsedouble (String s): converts S to double
float:
Double.parsefloat (String s): convert S to float
Int:
Integer.parseint (String s): convert s to int
Long:
Long.parselong (String s): convert S to Long
Explanation of the String.valueof () method in Java