File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Set and Map Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Set and Map" Watch "Set and Map" New topic

Set and Map

Raj Puri
Ranch Hand

Joined: Apr 24, 2003
Posts: 189
Whats is the difference between above two?
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1090
Hi Rajesh
A Set can not have duplicate values. While a map's Value can be duplicate but it's key can not be.
Let's take an example.
Consider the roll No. used in schools/colleges etc.
Here the roll no. is unique but the name may or may not be unique. So this is an example of a map where the name is the value(may be repeated) and roll no. is the key(unique).
You can consider a set as one, only containing values and that too unique.
Consider the set of all the english alphabets(A-Z). In this set we have only unique elements that is no alphabet can be repeated.
Hope that helps. Repost if it doesn't.
[ June 29, 2003: Message edited by: Anupam Sinha ]
Andres Gonzalez
Ranch Hand

Joined: Nov 27, 2001
Posts: 1561
Map: Key/value pair. One implementation of Map interface allow null key/values (hashmap) and others don't (hashtable). duplicate keys are not allowed.
Set: when you see a Set, think of no duplicates.
[ June 29, 2003: Message edited by: Andres Gonzalez ]

I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
I agree. Here's the link:
subject: Set and Map
It's not a secret anymore!