Casting

hihow to change double or int to a Stringthanks
[68 byte] By [S_Khan@java] at [2007-9-30 17:57:52]
# 1
double d = 5.0;String s = Double.toString(d);int i = 6;String s1 = Integer.toString(i);//orString s2 = String.valueOf(d);String s3 =
atmguy at 2007-7-6 18:26:54 > top of Java-index,Administration Tools,Sun Connection...
# 2

Also I would like to point out that you don't always need to code a cast

double d = 5.0;

String s = Double.toString(d);

int i = 6;

String s1 = Integer.toString(i);

//or

String s2 = String.valueOf(d);

String s3 = String.valueOf(i);

System.out.println("i="+i+" but d="+d);

Notice the string gets concatenated in the System.out.println just fine without any programming help. This will work for any string you are building up. For some things and speed it is better to use StringBuffer http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuffer.html instead of immutable Strings.

Martin3 at 2007-7-6 18:26:54 > top of Java-index,Administration Tools,Sun Connection...
# 3
And if you are running >=1.5 there is StringBuilder http://java.sun.com/j2se/1.5.0/docs/api/java/lang/StringBuilder.html
Martin3 at 2007-7-6 18:26:54 > top of Java-index,Administration Tools,Sun Connection...