What is the Difference Between a Set and a Map in Java ?

Main differences between a Set and a Map in Java are...

Duplicate Elements : A Set does not allow inserting duplicate elements. A Map does not allow using duplicate keys, but it allows inserting duplicate values for unique keys.

Null values : A Set allows inserting maximum one null value. In a Map we can have single null key at most and any number of null values.

Ordering : A Set does not maintain any order of elements. Some of sub-classes of a Set can sort the elements in an order like LinkedHashSet. A Map does not maintain any order of its elements. Some of its sub-classes like TreeMap store elements of the map in ascending order of keys.



You May Interest

What are the Different Types of Events Provided by Spring Framewo ...

What is the Importance of hashCode and equals Methods in Java ?

What is the Use of Interceptor Design Pattern in Java ?

What is the Difference Between sendRedirect and forward in a JSP ...

What is a WeakHashMap in Java ?