how do i convent int to string using toString() method.. the code i am using is public class Test28 { public static void main(String args[]) { Integer x=new Integer("4"); if (!(x instanceof String)) { x=x.toString(); System.out.println("x ix not string"); } else { System.out.println("x is string"); } } }
Bhasker Reddy
jafarali
Ranch Hand
Joined: Jul 15, 2000
Posts: 37
posted
0
Reddy, I think you have big mis-understanding about data types. any how in your code x=x.toString() is not correct it will fire a compile time error. Look at the following code. Integer ix = new Integer(400); Integer iy = new Integer(500); int x; int y; String sx; String sy; x = ix.intValue(); y = iy.intValue(); sx = ix.toString(); sx = iy.toString(); System.out.println(x+y); System.out.println(sx+sy); I hope this will clear your ideas!!!
[This message has been edited by jafarali (edited July 25, 2000).]
Praveen Zala
Ranch Hand
Joined: Jul 02, 2000
Posts: 118
posted
0
Hi there, I agree that the questioner needs to know more abt primitive datatypes and wrapper classes ! Anyhow, I even appreciate the excellent example above....... Praveen Zala
Helen Yu
Greenhorn
Joined: Jul 13, 2000
Posts: 29
posted
0
Hello, Can someone explain why my output is 900 500??? Thanks.