Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7625
  • Last Modified:

Difference between Map and Set

Difference between Map and Set
0
Manikandan Thiagarajan
Asked:
Manikandan Thiagarajan
  • 4
  • 2
  • 2
  • +1
2 Solutions
 
CEHJCommented:
A Map contains name-value pairs. A Set is simply a container for unique objects
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
>>A Set is simply a container for unique objects

could you explain this one
0
 
CEHJCommented:
Think of it as a list that can only contain unique objects as dictated by their equals method
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
olgavillamizarCommented:
A map has a pair for example
(key, object).
With key you can get the object

A set is just the object (object) just one.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Let's say you have an ArrayList al containing values "1", "2", "3", "4", "4", "5". So "4" is repeated here. Now create a Set out of it:

Set s = new HashSet ( al ) ;

Now 's' will contain the value "4" only once.
0
 
Manikandan ThiagarajanSenior consultantAuthor Commented:
>>Set s = new HashSet ( al ) ;

so this would avoid the duplicate values in array list
0
 
Mayank SAssociate Director - Product EngineeringCommented:
The array list will still contain those duplicates, the set will not.
0
 
CEHJCommented:
:-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now