1. String to int
int i = integer.valueof (my_str). Intvalue (); int i = integer.parseint (str);
2. String to Integer
Integer integer = integer.valueof (str);
3, int turn String
1.) String s = string.valueof (i); 2.) String s =3""
4, int turn to Integer
New Integer (i);
5, Integer turn String
Integer integer=string
6, Integer to int
int num=integer.intvalue ();
7, String turn Char
Char " 123 ". ToCharArray ();
8. Char to String
String s=ca.tostring (); // any type can be converted to a string type with ToString ()
9. Date
//DateCalendar calendar=calendar.getinstance ();intYear=calendar.Get(calendar.year);intMonth=calendar.Get(Calendar.month) +1;intDay=calendar.Get(calendar.date);//get today's date stringString today=java.text.dateformat.getdateinstance (). Format (Newjava.util.Date ());//get today's dateNewJava.sql.Date (System.currenttimemillis ());
10. Java Data type conversion:
import java.sql.Date; Public classTypechange { PublicTypechange () {}//Change the string type to the int type Public Static intstringtoint (String intstr) {integer integer; Integer=integer.valueof (INTSTR); return integer.intvalue (); } //Change int type to the string type Public StaticString inttostring (intvalue) {Integer integer=NewInteger (value); return integer.tostring (); } //Change the string type to the float type Public Static floatstringtofloat (String floatstr) {Float floatee; Floatee= float.valueof (floatstr); return floatee.floatvalue (); } //Change the float type to the string type Public StaticString floattostring (floatvalue) {Float Floatee=NewFloat (value); returnfloatee.tostring (); } //Change the string type to the Sqldate type Public StaticJava.sql.Date stringtodate (String datestr)//convert into Time { return java.sql.Date.valueOf (datestr); } //Change the sqldate type to the string type Public StaticString datetostring (java.sql.Date datee) {returndatee.tostring (); } Public Static voidMain (string[] args) {Java.sql.Date day; Day= Typechange.stringtodate ("2003-11-3"); String Strday=typechange.datetostring (day); System. out. println (Strday); }}
Java Type Conversion Summary