基本数据之间的转换

1、如何将字符串String转化为整数int

  int i = Integer.parseInt(str);

  int i = Integer.valueOf(my_str).intValue();

   注: 字串转成Double, Float, Long的方法大同小异。 
 
2、如何将字符串String转化为Integer

 

   Integer integer=Integer.valueOf(i)


3、如何将整数 int 转换成字串 String?

答:有三种方法:

  String s = String.valueOf(i);

  String s = Integer.toString(i);

  String s = "" + i;

注:Double, Float, Long 转成字串的方法大同小异。

4、如何将整数int转化为Integer

  Integer integer=new Integer(i)

 

5、如何 将Integer转化为字符串String

 

   Integer integer=String()

 

6、如何将Integer转化为int

   int num=Integer.intValue()

 

7、如何 将String转化为BigDecimal

 

   BigDecimal d_id=new BigDecimal(str)

原创   JAVA中long,float,int类型与String类型的相互转换: 收藏

<script type="text/javascript"> document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData("text"); if (text && text.length > 300) { text = text + "/r/n/n本文来自CSDN博客,转载请标明出处:" + location.href; clipboardData.setData("text", text); } }, 100); } } </script>

1 、将字符串Stirng 转换成整形IntFloatDoubleLong 的方法大同小异:有两种方法:  

Ø          int i = Integer.parseInt([String])

Ø          int i = IntegervalueOf(my_str).intValue();

2 、将整形 Int Float Double Long 转换成 String 的方法也大 同小异:有三种方法:

Ø          String s = StringvalueOf(i);

Ø          String s = Integer.toString(i);

Ø          String s = “”+i;

3 、将字符串 String 转换成 Date 型有一种方 法:

Ø          首先要包含 import java.text.*; ,然后定义 DateFormat format = new SimpleDateFormat(“yyyy-MM-dd”) 或者 DateFormat format = new SimpleDateFormat(“yyyy MM dd HH mm ss ”) 等。最后 Date date = format.parse(str);

4 、将 Date 型转换成 String 类型有一种方法:

   Ø 首先要包含 import java.text.*; ,然后定 义 DateFormat format = new SimpleDateFormat(“yyyy-MM-dd”)

       者 DateFormat format = new SimpleDateFormat(“yyyy MM dd HH mm ss ”) 等。最后 str =

            format.format(date)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值