File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "int to string conversion using toStirng()" Watch "int to string conversion using toStirng()" New topic

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))
System.out.println("x ix not string");
System.out.println("x is string");

Bhasker Reddy
Ranch Hand

Joined: Jul 15, 2000
Posts: 37
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();
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

Joined: Jul 13, 2000
Posts: 29
Can someone explain why my output is
hemant gome

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


I agree. Here's the link:
subject: int to string conversion using toStirng()
jQuery in Action, 3rd edition