| Author |
cast a String to an int, how?
|
Shuaib Gill
Ranch Hand
Joined: May 29, 2001
Posts: 62
|
|
Hi, Can someone tell me how to convert a type String to a type int. I have values in a hashtable and I am using the 'put' method to put a value in the hashtable. Here is the function public void setAgehashtable( int i, int age) { this.age=age; ageHashtable.put(new Integer(i),new Integer(age)); } Then I'm calling the 'getAgehashtable( int i)' method, like so public int getAgehashtable( int i) { ageInHashtableString=null; ageInHashtableString=(String)ageHashtable.get(new Integer(i)); return (int)ageInHashtableString; // error , why??? } I need to return the value as an integer, not String. I am trying to cast it from String to int, but an error results. Why? Please help.
|
programmer77
|
 |
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
|
|
Try return Integer.ParseInt(ageInHashtableString);
|
"JavaRanch, where the deer and the Certified play" - David O'Meara
|
 |
Shuaib Gill
Ranch Hand
Joined: May 29, 2001
Posts: 62
|
|
Thank you Cindy
|
 |
 |
|
|
subject: cast a String to an int, how?
|
|
|