This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

int to string conversion using toStirng()

 
Bhasker Reddy
Ranch Hand
Posts: 176
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
}
}
}
 
jafarali
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Can someone explain why my output is
900
500???
Thanks.
 
hemant gome
Greenhorn
Posts: 15
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code above
sx = iy.toString();
^^^^^ Please note this change
sy = iy.toString();

Hemant.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic