aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes int to string conversion using toStirng() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "int to string conversion using toStirng()" Watch "int to string conversion using toStirng()" New topic
Author

int to string conversion using toStirng()

Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
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
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
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
Hello,
Can someone explain why my output is
900
500???
Thanks.


hyby2000@yahoo.com
hemant gome
Greenhorn

Joined: Jul 24, 2000
Posts: 15
The code above
sx = iy.toString();
^^^^^ Please note this change
sy = iy.toString();

Hemant.


hem@nt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: int to string conversion using toStirng()