Home arrow static arrow Java Programming [Archive] - object to int
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - object to int
This topic has 1 reply on 1 page.

Posts:41
Registered: 2/23/04
object to int  
Jun 24, 2004 7:25 AM



 
How do I convert an object to an int?

i.e. Hashtable h;
h.put("ten", "10");
int ten = h.get("ten"); //how do I do this?

Thanks.
 

Posts:65
Registered: 02-05-22
Re: object to int  
Jun 24, 2004 7:30 AM (reply 1 of 1)



 
For the way the data is going into the Hashtable (use HashMap instead), try this...

String mapVal = ( String ) h.get( "ten" );

int ten;
if ( mapVal != null ) {
ten = Integer.parseInt( mapVal );
}

You could also put the value into the Map as an Integer object...
 
This topic has 1 reply on 1 page.