aspose file tools*
The moose likes Beginning Java and the fly likes Map vs. Set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Map vs. Set" Watch "Map vs. Set" New topic
Author

Map vs. Set

Ra Carter
Ranch Hand

Joined: Jul 30, 2005
Posts: 96
what is the difference between a Map and a Set?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
This is a question you can answer for yourself by looking at the Java SE Javadoc API. Both Map and Set are in the java.util package. If you have questions about what you read, let us know and we'll try and clarify.
[ March 12, 2007: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Ra Carter
Ranch Hand

Joined: Jul 30, 2005
Posts: 96
well... thanks for nothing since i already knew where the documentation was... but actually i was confused by HashSet vs. HashMap. I see now that sets are not key-value pairs but rather just a list of values that can not be duplicated.

did i state that correctly?
[ March 12, 2007: Message edited by: Ra Carter ]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14352
    
  22

"I see now that sets are not key-value pairs but rather just a list of values that can not be duplicated. did i state that correctly?"

Yes, that's right.

"well... thanks for nothing ..."

Looking at the documentation did help you find the anwer, didn't it?


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
The following code example will make the distinction clear.
A HashMap is a combination of <key,values> where the hashcode of the key determines the efficiency.

A HashSet is a set of values which hashcodes determines the efficiency and where each key has to be unique



I hope this will clearify it.


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Ra Carter:
well... thanks for nothing since i already knew where the documentation was...


Remember that we can only know what you are telling us. The more you tell us about what you already know, and what you already tried, the more effectively we can answer your question.

It's typically not very effective to insult those who are spending their leisure time trying to help you.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ra Carter
Ranch Hand

Joined: Jul 30, 2005
Posts: 96
the documentation did help... i was only joking with that comment but not really.. damn you people for not spoon feeding me answers!
 
 
subject: Map vs. Set