Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Casting Problem int to String

 
Reggie McDougal
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't cast an int to a string so I can compare the values.

I get an incovertable types error when In try the assign the value of i to j as a string so I can check that the value matched in an option select box.

Can someone point me in the right direction.

 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reggie,

can't cast an int to a string so I can compare the values.



You can check out the Java API for more info.

Joyce
[ October 25, 2004: Message edited by: Joyce Lee ]
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reggie,
I think you got error when you do this...



You cannot convert int primitive data type to String object directly..
You have to use wrapper class to do that, example



Hope this helps...
Correct me if I am wrong
daniel
 
Sean Stephens
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's another way to do it, though probably slower than using the Integer wrapper class:

String j = ""+i;
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sean Stephens:
Here's another way to do it, though probably slower than using the Integer wrapper class:

String j = ""+i;


This is an ugly hack - don't do it.

Another valid way to do it is

String.valueOf(i)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic