Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Object to int
02-28-2008, 02:40 PM (This post was last modified: 02-28-2008 02:44 PM by moonlight.)
Post: #1
Object to int
How can I convert an object to int.

For eg:
[java]
Hashtable ht = new Hastable();
ht.put("one", "1");
int one= ht.get("one"); // How?
[/java]
Find all posts by this user
Quote this message in a reply
02-28-2008, 02:44 PM
Post: #2
RE: Object to int
Its easy.

[java]
String value = (String) ht.get("one");
int one = Integer.parseInt(value);
[/java]
Find all posts by this user
Quote this message in a reply
02-28-2008, 02:58 PM
Post: #3
RE: Object to int
Please note that, parseInt method would throw a NumberFormatException if the given value is not a valid integer.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: