Java数据类型中String、Integer、int相互间的转换

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 = new Interger(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);

 

6.Integer转换成String

Integer it = new Integer(10);

String str = it.toString();

 

7.String转换成BigDecimal

BigDecimal bd = new BigDecimal(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());

posted on 2011-02-28 14:12 小罗 阅读(118472) 评论(5)  编辑  收藏

评论

# re: Java数据类型中String、Integer、int相互间的转换 2014-08-04 11:25 heh

6.Integer转换成String

Integer it;

String str = it.toString();

大哥你真有才。 这么恶心代码都能写出来  回复  更多评论   

# re: Java数据类型中String、Integer、int相互间的转换[未登录] 2015-01-28 17:34 啊啊

@heh
哈哈  回复  更多评论   

# protected void onProgressUpdate(integer... values) { //int value = values[0].intValue(); progress.setProgress(); } 2015-08-17 14:21 颜静

protected void onProgressUpdate(integer... values) {
//int value = values[0].intValue();
progress.setProgress();

}  回复  更多评论   

# re: Java数据类型中String、Integer、int相互间的转换[未登录] 2015-08-20 16:59 123

hao   回复  更多评论   

# re: Java数据类型中String、Integer、int相互间的转换 2016-01-12 11:10 jcc

@jcc
不好意思,看了下api,有这个方法,我可能是其他地方出问题了  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2015年8月>
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿

随笔分类

随笔档案

文章分类

文章档案

相册

收藏夹

Web Framework

常上的技术网站

查找资料的java网站

搜索

最新评论

阅读排行榜

评论排行榜