String与Integer互相转换

我不是女神ヾ 2022-04-01 11:14 354阅读 0赞
  1. //String转换Integer
  2. String str = "a";
  3. Integer i = null;
  4. if(str!=null){
  5. i = Integer.valueOf(str);
  6. }
  7. //方法一:Integer类的静态方法toString():
  8. Integer a = 2;
  9. String str = Integer.toString(a)
  10. //方法二:Integer类的成员方法toString():
  11. Integer b = 2;
  12. String str = b.toString();
  13. //方法三:String类的静态方法valueOf():
  14. Integer c = 2;
  15. String str = String.valueOf(c);

发表评论

表情:
评论列表 (有 0 条评论,354人围观)

还没有评论,来说两句吧...

相关阅读