A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Difference between Properties class and HashTable,HashMap
Joined: Nov 13, 2005
Oct 10, 2007 06:47:00
I have the following key value pairs:
These are stored in HashMap,HashTable.Also I use Properties class which loads these values from a property file.
Now I do the following within my code:
1)int i = ((Integer)hashTable.get("accountnumber")).intValue();
2)int j = ((Integer)hashMap.get("accountnumber")).intValue();
3)int k = ((Integer)properties.get("accountnumber")).intValue();
However I get a ClassCastException in the third case..Why?How does it differ from the previous 2 cases.
Also in the first 2 cases how can I cast the Object returned by get method to Integer?Doesn't that amount to narrow casting which should give ClassCasException??
Kindly clarify my doubts.
Joined: Feb 25, 2007
Oct 10, 2007 07:12:00
Properties only store values as strings. So, you can not cast it to Integer. You can use a Integer.parseInt() for getting int from the
, a better way to API!
I agree. Here's the link:
subject: Difference between Properties class and HashTable,HashMap
boxing,unboxing,for each and varargs
Question on sum of syracuse sequence (memorization question)
Banking with Threads
overloaded func, both accept same no and type of parameters
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014