java 字符串与数据之间的转换

字符串转整型

调用Integer的方法

String转Integer

使用构造方法:Integer i=new Integer(8);
使用类方法:Integer i=Integer.valueOf(String)

String转int

使用类方法:

  • static int parseInt(String s)
    将字符串参数解析为带符号的十进制整数。 int a=Integer.parseInt(8);
  • static int parseInt(String s, int radix)
    将字符串参数解析为第二个参数指定的基数中的有符号整数。 int a=Integer.parseInt(8,2);//以二进制数转换8

整型转字符串

使用String的类方法String s=String.valueOf(int \ Integer)
其他的转Double,Float等等都是一样的。

猜你喜欢

转载自blog.csdn.net/qq_36976201/article/details/112829715
今日推荐