The String data type is converted to seven data types, including long, int, double, float, boolean, and char. floatboolean
String c = "123456 ";
// To convert String data to int, double, float, long, and other data types, the data must be composed of numbers,
// When String data is composed of Chinese characters or letters and is converted to int, double, float, long, and other data types, the program reports an error.
// Convert String type to long type
// When the String type data is converted to the long type, the String type data must be composed of numbers.
Long n = Long. parseLong (c );
System. out. println ("String type converted to long type:" + n );
// Convert String to int type
// When String type data is converted to int type, String type data must be composed of numbers.
Int I = Integer. parseInt (c );
System. out. println ("String converted to int type:" + I );
// Convert String to double type
// When String type data is converted to double type, String type data must be composed of numbers.
Double m = Double. parseDouble (c );
System. out. println ("String converted to double type:" + m );
// Convert String type to float type
// When the String type data is converted to the float type, the String type data must be composed of numbers.
Float M = Float. parseFloat (c );
System. out. println ("String type converted to float type:" + M );
// Convert the String type to the Object type. If the conversion is not involved, the String value is directly assigned to the Object.
Object L = c;
System. out. println ("String converted to Object:" + L );
// Convert String type to boolean type
String C = "true ";
// When the value of the String type is true/false, true/false is output directly.
Boolean N = Boolean. parseBoolean (C );
System. out. println ("String type converted to boolean type:" + N );
// When the String type data value is composed of numbers, characters, Chinese characters, or a combination, false is output.
Boolean o = Boolean. parseBoolean (c );
System. out. println ("String type converted to boolean type:" + o );
// Convert String type data to char type data
// When String type data is converted to char type data, an array of the char type must be used to accept
Char [] O = c. toCharArray ();
System. out. print ("converting String type data to char type data :");
For (int num = 0; num <O. length; num ++ ){
System. out. print (O [num] + "\ t ");
}