• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how will i get my values from collection?

 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after running this code i get hashcode values..i want to get the primitive values the object is holding???how do i do that..
how do i get individual entry set and keyset seperately???
 
Phungsuk Wangdu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont get it
what is question
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set s=lh.keySet(); will do it...you can also put generics to it
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using maps...i want solution for maps....thanks
 
Raju Champaklal
Ranch Hand
Posts: 521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dude you get a set when you want keyset
 
Phungsuk Wangdu
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh i am sorry i didnt knew this was against rules
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is not helping......
 
W. Joe Smith
Ranch Hand
Posts: 710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Carter wrote:check your pm


Please UseTheForumNotEmail to respond to questions. If there is a solution there are many others (myself included) that would like to see it.

Thanks!
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not that hard. If you compile it then you'll get this message:
wouter@wouter-laptop:~/temp$ javac TurtleTest.java
TurtleTest.java:39: cannot find symbol
symbol : class Entry
location: class TurtleTest
for (Entry<Turtle, Turtle> t:lh.entrySet())
^
1 error


Saying that it cannot find that class. So just import it



But then it still does not want you want it to do because the hashCode method has not been implemented (A Map uses hashCode and equals to determine if objects are equal, not the comparable interface).
So implement the hashCode and equals methods properly. Total code:

And then the output is 3 which is what we wanted/expected.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I forgot:

And if you want to output some values then use the Entry methods getKey() and getValue()
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are a genius !!!thanks Wouter.....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic