Make Selenium Easy

#1. Difference Between List And Set In Java

A Collection in Java is an Object that represents a group of Objects and the Collection Framework consists of multiple classes and interfaces which can be used for various data manipulation operations.

List and Set both are Interfaces in Java and extend the most basic interface Collection interface. We will learn the basic differences between both.

  1. List stores the element in the order it is inserted whereas Set does not. However, an implemented class of Set named LinkedHashSet stores elements in the insertion order.
  2. Since List is an ordered collection we can use the index to access any element directly which is not possible in Set.
  3. The List can contain duplicate elements but the Set can not.
  4. We can have multiple NULL elements in a List but the Set can have only one NULL element.
  5. The important implemented classes of List are ArrayList, LinkedList and Vector. LinkedHashSet, TreeSet and HashSet are important implemented classes of the Set interface.

Thanks for reading.

Author: Amod Mahajan

A software Tester who is paid to judge products developed by others. Currently getting paid in American Dollars. Writing technical posts and creating YouTube videos are my hobbies.

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

#1. Difference Between List And Set In Java

by Amod Mahajan time to read: 1 min
0
%d bloggers like this: