| Author |
String to Integer Conversion
|
Jas Oberai
Ranch Hand
Joined: Jan 16, 2005
Posts: 231
|
|
Hey Friends, Can you just tell me how to change a string like this to an Integer.I know this is really stupid quetion..but any help would be appreciated.
|
SCJP 1.4 (88%)<br />SCWCD 1.4 (88%)
|
 |
Stephen Huey
Ranch Hand
Joined: Jul 15, 2003
Posts: 618
|
|
Check out the 3rd constructor here: http://java.sun.com/j2se/1.3/docs/api/java/lang/Integer.html
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
But of course, new Integer("2.00"), just like Integer.parseInt("2.00"), throws an exception, because 2.00 is a double, not an int. If you have a String which may contain an arbitrary number, I think your best bet would be something like int num = (int) Double.parseDouble("2.00");
|
[Jess in Action][AskingGoodQuestions]
|
 |
Jas Oberai
Ranch Hand
Joined: Jan 16, 2005
Posts: 231
|
|
thanks ernest, Your are rite..it throwed an Exception and your code worked.Thanks.
|
 |
 |
|
|
subject: String to Integer Conversion
|
|
|