• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieving Data from HashMap  RSS feed

 
Anthony D'Souz
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have created a Hashmap containing 2 arraylist but i am not able to retrieve the arraylist back from the HashMap. I am not able to use generics fordoing the same(since my java compiler does not supports the same), hence i tried out this piece of code to loop through the hashmap entries:



but its throwing me a class cast exception in the above line. I am not able to figure out how to solve this problem. Please help.

Thanks
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is the version of the JDK you are using? check javac -version from command line.
Generics were introduced in Java 5 so you need to be having JDK 5.0 and later for generics to be supported.

Also show us the code which you are trying.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hashmap.keySet returns a Set containing the keys from the Hashmap. My guess is that it's the values you want - for that use Hashmap.values. Note that this returns a Collection instance rather than a Set but that shouldn't affect your code.
 
Mohamed Sanaulla
Bartender
Posts: 3185
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I didnt get the question clearly. Only after I read Joanne's reply that I think the issue is different from what I have interpreted.
Its always ideal to post a SSCCE. And you should be trying out values() method as told above.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!