Public classchangetype { Public Static voidMain (string[] args) {String ar= "true";//string to Boolean, as long as it is not "true" and the result is false; BooleanAR1 =Boolean.parseboolean (AR); if(AR1) {System.out.println ("true");//the result is true;} String Str= "12";//String Goto int intm =integer.parseint (str); System.out.println (m); String STR0= "12.6";//convert string to double Doublex =double.parsedouble (STR0); SYSTEM.OUT.PRINTLN (x); inty = 5; String str1= y+ ""; System.out.println (STR1); intflag = 100;//int to string, any type connected to a string becomes a string type. Not recommended for useString a = flag+ ""; System.out.println (a); intFLAG0 = 200;//int to string using string.valueof ();String STR3 =string.valueof (FLAG0); System.out.println (STR3); floath = 12.6f;//float to int, from high to low must be forced type conversion, loss precision changed to intW = (int) H; System.out.println (w); //The result is floatc = 89.6666f; Doubles =C; System.out.println (s); //The result is 89.666677987979 DoubleE = 78.999999999; floato = (float) E; System.out.println (o); //The result is }}
Java-Conversions between basic data types