This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how will i get my values from collection? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "how will i get my values from collection?" Watch "how will i get my values from collection?" New topic
Author

how will i get my values from collection?

maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
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 karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
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 karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
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 karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
you are a genius !!!thanks Wouter.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how will i get my values from collection?