1.Integer转换成int的方法
Integer i = new Integer(10);
int k = i.intValue();
即Integer.intValue();
2.int转换成Integer
int i = 10;
Integer it = new Integer(i);
3.String转换成int的方法
String str ="10";
Integer it = newInterger(str);
int i = it.intValue();
即:int i = Integer.intValue(string);
4.int转换成String
int i = 10;
(1)String s =String.valueOf(i);
(2)String s =Ingeger.toString(i);
(3)String s = "" +i;
5.String转换成Integer
String str = "10";
Integer it =Integer.valueOf(str);
或者:Integer it = Integer.parseInt(str);
6.Integer转换成String
Integer it = new Integer(10);
String str = it.toString();
或者 String str = it + "";
或者String.valueOf(it);
7.String转换成BigDecimal
BigDecimal bd = newBigDecimal(str);
8.日期
Calendar calendar =Calendar.getInstance();
int year =calendar.get(Calendar.YEAR);
int month =calendar.get(Calendar.MONTH)+1;
int day =calendar.get(Calendar.DATE);
//获取今天的日期字符串
String today =java.text.DateFormat.getDateInstance().format(new java.util.Date());
//获取今天的日期
new java.sql.Date(System.currentTimeMillis());
9.字符数组与字符串之间的转换
- char[] a={ 'a ', 'b ', 'c '};
- String b=new String(a);//字符数组到字符串
- char[] c=b.toCharArray();//字符串转换成字符数组