(非原创)code
一.String 转为int类型的方法orm
1)Integer.parseInt([String])字符串
2)Integer.valueOf([String]).intValue();get
接受如下语法给出的十进制,十六进制,八进制数字.it
3)Integer.decode([String]):io
例如:form
int a = Integer.decode("0144");//八进制转换结果为100object
int b= Integer.decode("123");//十进制转换结果为123date
int c= Integer.decode("0x123");//16进制转换结果为291map
Integer.decode([String]):加负号也能够转化,不过字符串不能有空格,不然报NumberFormatException异常
字符串转成Double,Float,Long方法相似
------------------------------------------------
二.int转化为String 类型的方法
String s= String.valueOf(i);
String s =Integer.toString(i);
String s = " " + i;
-----------------------------------------------
三.Object 转为Int
若是object是byte,short,int,char类型生成的,不用转换直接赋值就能够
Object 为字符串类型,先把Object 转为String 再转为Int
例如: String myInt = "123";
Object os = myInt;
int b = Integer.parseInt((String)os);
例如:
Integer.parseInt(map.get("TRADE_TYPE").toString())
--------------------------------------------------------
四.Object 转换为String类型
String title =String.valueOf(obj[2]);
String content = String.valueOf(obj[3]);
---------------------------------------------------------
五.Object 转换为Date类型:
SimpleDateFormat能够将String 转化为Date,也能够将Date转为String.
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-mm-dd");
date 转为String
String indate = sdf.format(date);
String转为date
Date indate = sdf.parse(String);