- 1.toString 适用于int类型
public class test {
public static void main(String[] args) {
int i = 777;
String str = Integer.toString(i);
System.out.println(str);
}
}
- 2.valueOf 适用于int、double、boolean和Object类型
public class test {
public static void main(String[] args) {
int i = 777;
String str = String.valueOf(i);
System.out.println(str);
}
}
- 3.使用+,java内自动将数字转化成字符串
public class test {
public static void main(String[] args) {
int i = 36;
String str = i + "";
System.out.println(str);
}
}
- 4. format
public class test {
public static void main(String[] args) {
int i = 36;
String str = String.format("%d",i);
System.out.println(str);
}
}
标签:java,String,int,System,整数,static,str,字符串,public From: https://blog.csdn.net/2202_75779100/article/details/140085286