How do I convert from int to String?

后端 未结 20 3262
不思量自难忘°
不思量自难忘° 2020-11-21 23:40

I\'m working on a project where all conversions from int to String are done like this:

int i = 5;
String strI = \"\" + i;
         


        
20条回答
  •  情书的邮戳
    2020-11-22 00:13

    There are many way to convert an integer to a string:

    1)

    Integer.toString(10);
    

    2)

     String hundred = String.valueOf(100); // You can pass an int constant
     int ten = 10;
     String ten = String.valueOf(ten)
    

    3)

    String thousand = "" + 1000; // String concatenation
    

    4)

    String million = String.format("%d", 1000000)
    

提交回复
热议问题