zhangwuji

int –> String

int i=123;

String s="";

第一种方法:s=i+""; //会产生两个String对象

第二种方法:s=String.valueOf(i);  //直接使用String类的静态方法,只产生一个对象

第三种方法:Integer.toString(i);

String –> int

s="123";

int i;

第一种方法:i=Integer.parseInt(s);  //直接使用静态方法,不会产生多余的对象,但会抛出异常

第二种方法:i=Integer.valueOf(s).intValue();  //Integer.valueOf(s) 相当于 new Integer(Integer.parseInt(s)),也会抛异常,但会多产生一个对象

【Double, Float, Long ,Byte, Short与字符串之间的转换方法大同小异】

分类:

技术点:

相关文章:

  • 2021-09-13
  • 2021-08-18
  • 2021-11-15
  • 2021-12-24
  • 2021-07-13
  • 2021-12-26
  • 2021-12-06
  • 2021-11-05
猜你喜欢
  • 2021-09-13
  • 2021-09-13
  • 2021-12-08
  • 2021-11-06
  • 2021-11-05
  • 2021-09-13
相关资源
相似解决方案