String in Java is a final class, and the string is not modified. The String type is often used in projects. Here are more commonly used String data type conversion:
String data types are converted to seven types of data types such as Long, Int, Double, Float, Boolean, Char
Copy code code as follows:
* Data type conversion
* @Author administrator
*
*/
public class data type conversion {
Public Static Void Main (String [] args) {{
String C = "123456";
// When the String type data is converted to data types such as int, double, float, long and other data, its data must be composed of numbers.
// When the String type data is converted to int, dough, float, long and other data types when it is composed of Chinese characters or letters, the program reports an error
// String Types Convert to Long type <br /> Copy code code as follows:
// String Type data When converting to LONG type, String type data must be a number composition
long n = long.parselong (c);
System.out.println ("String types convert to long type:"+n);
// string convert to int type
Copy code code as follows:
// String type data When converting to int type, the data of String type must be a number composition
int i = integer.parseint (c);
System.out.println ("String convert to int type:"+i);
// string converted to double type <br /> Copy code code as follows: as follows:
// String Type data When converting to Double type, String type data must be a number composition
double m = double.parsed allowance (c);
System.out.println ("String converted to dough type:"+m);
// String Types Convert to Type Float Type
Copy code code as follows:
// String Type data When converting to Float type, the data of String type must be a number composition
float m = float.parsefloat (c);
System.out.println ("String type converted into type Float type:"+m);
// The string type converted into Object type does not involve conversion directly to the value of string to Object
Copy code code as follows:
Object l = C;
System.out.println ("String convert to object:"+L);
// String Types Converted into Boolean Type <br /> Copy code Code as follows:
String c = "true";
// When the string type data value is True/False, directly output True/False
boolean n = boolean.parseboolean (+c);
System.out.println ("String types convert to Boolean type:" n);
// When the string type data value is numbers, characters, Chinese characters, or hybrid composition, the output FALSE
boolean o = boolean.parseboolean (c);
System.out.println ("String type converted into Boolean type:"+o);
// String Type data Converted to Char type data <br /> Copy code code is as follows:
// When the String type data is converted into a Char type data, you need to use a CHAR type array to accept
char [] o = c.tochararray ();
System.out.print ("String type data converts to Char type data:");
for (int num = 0; num <o.length; num ++) {
System.out.print (o [num]+"/t");
}
System.out.println ("/n");
// int, dough, boolean, char, float, long, object type data converts to string
// int Type converted into string type <br /> Copy code code as follows: as follows:
int H = 123456;
String l = string.valueof (h);
System.out.println ("INT type converted into string type:"+L);
// Double type to string
Copy code code as follows:
double a = 1.1;
String a = string.valueof (a);
System.out.println ("Double type to string:"+a);
// Boolean Type to String Type <br /> Copy code code as follows:
boolean b = false;
String b = string.valueof (b);
System.out.println ("Boolean type to string type:"+b);
// Char type to string type <br /> Copy code code as follows:
char d = 'a';
String d = string.valueof (d);
System.out.println ("Char type to string type:"+d);
// CHAR type array converted into string type <br /> Copy code code as follows:
char [] e = {'a', 'b', 'c'};
String e = string.valueof (e);
System.out.println ("Char type array converted to string type:"+e);
// CHAR type arrays are converted into string type copy code code as follows: below:
char [] f = {'a', 'b', 'c', 'd'};
String f = string.valueof (f, 0, 3);
System.out.println ("Several of the data in the type arrays of the Char type converted into string type:"+f);
// Float type Convert to string type <br /> Copy code code as follows:
Float g = 123;
String g = string.valueof (g);
System.out.println ("Float type converted into string type:"+g);
// Long type converted into string type <br /> Copy code code as follows:
long j = 123342;
String j = string.valueof (j);
System.out.println ("Long type converts to string type:"+j);
// Object types convert to string <br /> Copy code code as follows:
Object k = C;
String k = string.valueof (k);
System.out.println ("Object types into string type:"+k);
System.out.println ("/n");
The above code is a detailed explanation of the String data type conversion in Java. I hope everyone likes it.