Tuesday, March 12, 2013

Difference between Set and List in Java

Set:

1. A set represents a collection of elements . Order of the elements may change in the set.
2. Set will not allow duplicate values to be stored.
3. Accessing elements by their index(position number) is not possible in case of sets.
4.Sets will not allow null elements.

List:

1. A List represents ordered collection of elements . List preserves the order of elements in
which they are entered.
2. List will allow duplicate value.
3.Accessing elements by index is possible in lists.
4. Lists allow null elements to be stored.

No comments:

Post a Comment