Skip to content

Instantly share code, notes, and snippets.

@poetries
Created May 10, 2016 09:06
Show Gist options
  • Save poetries/22f7a02d3d63e2ac52277e658df4a916 to your computer and use it in GitHub Desktop.
Save poetries/22f7a02d3d63e2ac52277e658df4a916 to your computer and use it in GitHub Desktop.
整数转换为字符串的四种方法
//把整型转化为字符串三种方法
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