Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Map vs. Set

 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between a Map and a Set?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15437
41
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"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?
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ra Carter
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the documentation did help... i was only joking with that comment but not really.. damn you people for not spoon feeding me answers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic