How do I convert from int to String?

后端 未结 20 2778
不思量自难忘°
不思量自难忘° 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:15

    String strI = String.valueOf(i);
    
    String string = Integer.toString(i);
    

    Both of the ways are correct.

提交回复
热议问题