Difference between List and Set in Java

What is difference between List and Set in Java is a very popular Java  interview question.

List vs Set in Java

1.The Fundamental difference between List and Set in Java is that List generally allow duplicate objects where as Set do not allow duplicate objects.

2. List is an Ordered Collection (List maintains insertion order of elements) where as Set is an unordered Collection(Set in Java does not  maintain any order)

3.List objects are accessible by index(list.get(index) method can be used ) where as Set obejcts are not accessible by index there is no such method available for set.

4. Implementation of List interface in Java are ArrayList, Vector and LinkedList. While implementation of Set interface in java are HashSet, TreeSet and LinkedHashSet.

Advertisements
This entry was posted in Java. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s