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

 

http://blog.youkuaiyun.com/u012246458/article/details/49359495

 

 

  1. 1.Integer转换成int的方法  
  2.   
  3. Integer i = new Integer(10);   
  4. int k = i.intValue();  
  5. 即Integer.intValue();  
  6.   
  7.    
  8.   
  9. 2.int转换成Integer  
  10.   
  11. int i = 10;  
  12.   
  13. Integer it = new Integer(i);  
  14.   
  15.    
  16.   
  17. 3.String转换成int的方法  
  18.   
  19. String str = "10";    
  20. Integer it = new Interger(str);    
  21.   
  22. int i = it.intValue();    
  23.   
  24. 即:int i = Integer.intValue(string);  
  25.   
  26.    
  27.   
  28. 4.int转换成String  
  29.   
  30. int i = 10;  
  31.   
  32. (1)String s = String.valueOf(i);  
  33.   
  34. (2)String s = Ingeger.toString(i);  
  35.   
  36. (3)String s = "" + i;  
  37.   
  38.    
  39.   
  40. 5.String转换成Integer  
  41.   
  42. String str = "10";  
  43.   
  44. Integer it = Integer.valueOf(str);  
  45.   
  46.    
  47.   
  48. 6.Integer转换成String  
  49.   
  50. Integer it = new Integer(10);  
  51.   
  52. String str = it.toString();  
  53.   
  54.    
  55.   
  56. 7.String转换成BigDecimal  
  57.   
  58. BigDecimal bd = new BigDecimal(str);  
  59.   
  60.    
  61.   
  62. 8.日期  
  63.   
  64. Calendar calendar = Calendar.getInstance();  
  65. int year = calendar.get(Calendar.YEAR);  
  66. int month = calendar.get(Calendar.MONTH)+1;  
  67. int day = calendar.get(Calendar.DATE);  
  68.   
  69. //获取今天的日期字符串  
  70. String today = java.text.DateFormat.getDateInstance().format(new java.util.Date());  
  71. //获取今天的日期  
  72. new java.sql.Date(System.currentTimeMillis());
  73.  
  74.  
  75. 9.Double 转换成 String
  76. //方式一 
  77.   String.valueOf(d);
  78. //方式二
  79.  String str = ""+d;
  80.  
  81.  

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值