Forums Register Login

how will i get my values from collection?

+Pie Number of slices to send: Send
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???
+Pie Number of slices to send: Send
i dont get it
what is question
+Pie Number of slices to send: Send
Set s=lh.keySet(); will do it...you can also put generics to it
+Pie Number of slices to send: Send
i am using maps...i want solution for maps....thanks
+Pie Number of slices to send: Send
dude you get a set when you want keyset
+Pie Number of slices to send: Send
oh i am sorry i didnt knew this was against rules
+Pie Number of slices to send: Send
it is not helping......
+Pie Number of slices to send: Send
 

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!
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
I forgot:

And if you want to output some values then use the Entry methods getKey() and getValue()
+Pie Number of slices to send: Send
you are a genius !!!thanks Wouter.....
Look ma! I'm selling my stuff!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1289 times.
Similar Threads
Convert an Object to ByteArray
overiding hashCode method from Object Class
Regarding Hashcode
hashcodes
collections.sort compiler error?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 15, 2024 23:49:37.