Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Set and Map

 
Raj Puri
Ranch Hand
Posts: 189
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whats is the difference between above two?
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic