aspose file tools*
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Set and Map" Watch "Set and Map" New topic
Author

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: 1088
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.
HTH
[ 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: http://aspose.com/file-tools
 
subject: Set and Map