Different possible ways to convert integer into String!
The first one is the easiest and the simplest:
int i = 1234;
String s = "" + i;
String s = "" + i;
The second method uses the valueOf()function of the String class:
int i = 1234;
String s = String.valueOf(i);
String s = String.valueOf(i);
The third one requires wrapper class Integer and uses its toString() function:
int i = 1234;
String s = new Integer(i).toString();
String s = new Integer(i).toString();
One more program
public class Test { public static void main(String[] args) {
// First Method
System.out.println(String.valueOf(12345));
// Second Method
System.out.println(Integer.toString(12345));
// Third Method
System.out.println(new Integer(12345).toString());
// Fourth Method
System.out.println(String.format("%d", 12345));
// Fifth Method
System.out.println(new StringBuffer().append(12345).toString());
// Six Method
System.out.println(new StringBuilder().append(12345).toString()); // Seventh Method
int num = 12345; String numString = "" + num; System.out.println(numString);
}
}
Output
12345
12345
12345
12345
12345
12345
12345
// First Method
System.out.println(String.valueOf(12345));
// Second Method
System.out.println(Integer.toString(12345));
// Third Method
System.out.println(new Integer(12345).toString());
// Fourth Method
System.out.println(String.format("%d", 12345));
// Fifth Method
System.out.println(new StringBuffer().append(12345).toString());
// Six Method
System.out.println(new StringBuilder().append(12345).toString()); // Seventh Method
int num = 12345; String numString = "" + num; System.out.println(numString);
}
}
Output
12345
12345
12345
12345
12345
12345
12345
I have read your blog its very attractive and impressive. I like it your blog.
ReplyDeleteJava Training in Chennai Core Java Training in Chennai Core Java Training in Chennai
Java Online Training Java Online Training JavaEE Training in Chennai Java EE Training in Chennai
Hello Guys don't delay Mumbai trip because Taaj Mumbai escorts girls agency wait for you, write-my-essay.cheap it's a great dating hub, so you can enjoy with us according your date and time.
ReplyDeleteThanks for sharing the article...
ReplyDeleteLucknow escorts
I really liked your post very much thanks foir sharing it...
ReplyDeleteCall Girl in Jaipur
Call Girl in Jaipur
Call girl in Jaipur
Call Girl in Delhi
Call Girl in Guwahati
Call Girl in Guwahati
Call Girl in Guwahati
Call Girl in Guwahati
Call Girl in Aerocity
Call Girl in Lucknow
You can book call girls in Guwahati or escorts in Guwahati for incall facility or outcall
ReplyDeleteFacility as and when required. To book Guwahati call girls you
can visit the following links
Call Girl in Guwahati
Guwahati Call Girl