• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

how will i get my values from collection?

 
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???
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i dont get it
what is question
 
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......
 
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!
 
Bartender
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
Bartender
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.....
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!