java2db

Difference between Set List and Map in java Collections Framework



Set and List are sub interfaces to java.util.Collection interface.Map is an interface which is having key and value pairs.The main Differences between Set List and Map in java Collections Framework as follows:

Set

Set List and Map in java Collections Set interface is an unordered collection  and  it won’t allow duplicate elements .

Set List and Map in java Collections But it allows null elements  ie.. we can add null elements to Set implementations.

Set List and Map in java Collections We cannot get elements  by  key or index . Set is not synchronized .

List

Set List and Map in java Collections List interface is a ordered collection and it allows duplicate , null elements .

Set List and Map in java Collections We can get elements by index . Like Set , List also a not synchronized collection .

Map

Set List and Map in java Collections Map interface is a unordered collection , it allows duplicate elements but not duplicate keys .

Set List and Map in java Collections It allows null elements but not null keys .

Set List and Map in java Collections Map is not a synchronized collection .

 

 

All Methods from Set List and Map in java Collections :

Set List and Map in java Collections Set List and Map in java Collections Set List and Map in java Collections

 Example for Set List and Map in java Collections :

Execution Result:

 

Set List and Map in java Collections Use Collections.synchronizedSet(Set set) to make Set as synchronized.
Set List and Map in java Collections Use Collections.synchronizedList(List list) to make List as synchronized.
Set List and Map in java Collections Use Collections.synchronizedMap(new HashMap(…)) for synchronized Map.




Related Posts :

No related posts found!

   [will not be published]



^ <