z-cg

数字转字符串

方法一:使用String类的静态方法valueOf()

方法二:先把基本类型装箱为对象,然后调用对象的toString方法

                   

 1 public class TestNumber {
 2   
 3     public static void main(String[] args) {
 4         int i = 5;
 5          
 6         //方法1
 7         String str = String.valueOf(i);
 8          
 9         //方法2
10         Integer it = i;
11         String str2 = it.toString();
12          
13     }
14 }

字符串转数字

调用Integer的静态方法parseInt

 1 public class TestNumber {
 2   
 3     public static void main(String[] args) {
 4  
 5         String str = "999";
 6          
 7         int i= Integer.parseInt(str);
 8          
 9         System.out.println(i);
10          
11     }
12 }

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-09-14
  • 2022-01-12
  • 2022-01-21
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-08
  • 2022-12-23
  • 2021-05-25
  • 2022-01-29
  • 2022-12-23
  • 2022-01-29
  • 2022-02-13
相关资源
相似解决方案