| Author |
how will i get my values from collection?
|
maggie joseph
Ranch Hand
Joined: Dec 29, 2009
Posts: 185
|
|
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
Joined: Nov 04, 2009
Posts: 114
|
|
i dont get it
what is question
|
 |
Raju Champaklal
Ranch Hand
Joined: Dec 10, 2009
Posts: 521
|
|
|
Set s=lh.keySet(); will do it...you can also put generics to it
|
scjp 1.6 91%, preparing for scmad
"Time to get MAD now.. we will get even later"....by someone unknown
|
 |
maggie joseph
Ranch Hand
Joined: Dec 29, 2009
Posts: 185
|
|
|
i am using maps...i want solution for maps....thanks
|
 |
Raju Champaklal
Ranch Hand
Joined: Dec 10, 2009
Posts: 521
|
|
|
dude you get a set when you want keyset
|
 |
Phungsuk Wangdu
Ranch Hand
Joined: Nov 04, 2009
Posts: 114
|
|
|
oh i am sorry i didnt knew this was against rules
|
 |
maggie joseph
Ranch Hand
Joined: Dec 29, 2009
Posts: 185
|
|
it is not helping......
|
 |
W. Joe Smith
Ranch Hand
Joined: Feb 10, 2009
Posts: 710
|
|
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!
|
SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
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.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
I forgot:
And if you want to output some values then use the Entry methods getKey() and getValue()
|
 |
maggie joseph
Ranch Hand
Joined: Dec 29, 2009
Posts: 185
|
|
you are a genius !!!thanks Wouter.....
|
 |
 |
|
|
subject: how will i get my values from collection?
|
|
|