Created
May 10, 2016 09:06
-
-
Save poetries/22f7a02d3d63e2ac52277e658df4a916 to your computer and use it in GitHub Desktop.
整数转换为字符串的四种方法
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//把整型转化为字符串三种方法 | |
public class TestInt | |
{ | |
public static void main(String[] args) | |
{ | |
int i = 345; | |
String str; | |
//第一种方法 | |
str = i+""; | |
System.out.println("str = " +str); | |
//第二种方法 | |
Integer it = new Integer(i); | |
str = it.toString(); | |
System.out.println("str = " +str); | |
//第三种方法 | |
str = Integer.toString(i); | |
System.out.println("str = " +str); | |
//第四种 | |
str = String.valueOf(i); | |
System.out.println("str = " +str); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment