What are the difference between Set and List.in Java ?
![]() Don't want to miss a single bit? Subscribe By Email for Daily Jobs |
The Java 2 container library takes the issue of “holding your objects” and divides it into two distinct concepts:
1. Collection: a group of individual elements, often with some rule applied to them. A List must hold the elements in a particular sequence, and a Set cannot have any duplicate elements. (A bag, which is not implemented in the Java container library—since Lists provide you with enough of that functionality—has no such rules.)
2. Map: a group of key-value object pairs. At first glance, this might seem like it ought to be a Collection of pairs, but when you try to implement it that way the design gets awkward, so it’s clearer to make it a separate concept. On the other hand, it’s convenient to look at portions of a Map by creating a Collection to represent that portion. Thus, a Map can return a Set of its keys, a Collection of its values, or a Set of its pairs.
Maps, like arrays, can easily be expanded to multiple dimensions without adding new concepts; you simply make a Map whose values are Maps (and the values of those Maps can be Maps, etc.).
Related Articles
- What are collection objects in VB.net ?
- What are the differences between ArrayList and LinkedList types in Java ?
- What are Vectors in C++(Object Oriented Programming) and how are they used ?
- What are containers in C++ and in Object Oriented Programming ? Which objects are available as containers ?
- What is the difference between Abstract Widget Toolkit (AWT) and Swing ?


