• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

SoftwareTestingo - Interview Questions, Tutorial & Test Cases Template Examples

  • Home
  • Test Case Examples
  • Interview Questions
  • Interview Questions Asked
  • Java
  • Selenium
  • Manual Testing
  • SQL Tutorial For Beginners
  • Difference
  • Tools
  • Contact Us
  • Search
SoftwareTestingo » Difference » Difference Between List VS Set In Java

Difference Between List VS Set In Java

Last Updated on: April 23, 2019 By Softwaretestingo Editorial Board

What We Are Learn On This Post

  • List vs Set In Java
  • When to use List?
  • When to use Set?

List VS Set In Java: In this article, we will discuss the difference between List and Set in detail i.e.; List v/s Set

Read: HashMap Vs Hashtable In Java

Both interfaces directly extend Collection interface, but they are a few differences between them Lets us move on and discuss key differences between them

List vs Set In Java

List
Set
It stores elements according to insertion order, insertion order is preserved Set stores elements in random order, as it uses hashing techniqueInsertion order isn’t preserved
While iterating List items, elements will be retrieved as per insertion order While iterating Set items, elements will be retrieved in random order
It allows duplicate elements Set doesn’t allow duplicate elements i.e.; it stores only unique elementsNote: if the same element is added again, there won’t be any compile-time or runtime error, just that add() method returns false;
Any number of the NULL object is allowed to add to the List Maximum of one NULL is allowed
Read Also: java interview questions

When to use List?

  • If the business requirement is to preserve insertion order and
  • adding duplicate elements is not a big concern
  • then List is the good choice to store the group of elements
  • Example: it could be ArrayList or LinkedList or Vector, etc

When to use Set?

  • If the business requirement is to avoid storing duplicate elements
  • And storing only unique elements
  • Where insertion order isn’t a big factor while iterating items
  • then Set is the good choice to store the group of elements
  • Example: it could be HashSet, etc

If you like SoftwareTestingo and would like to contribute something to this community, then you can also write an article using our Contact us page or mail your article to admin@softwaretestingo.com. So that we can review your article and that also appears on the SoftwareTestingo.com main page and help other Testers.

Please Improve this article, if you find anything incorrect by commenting on the comment box and we are happy to work on the article to maintain the accuracy and improvement.

    Difference Between Agile vs Waterfall
    Difference Between Agile vs Waterfall Methodology
    Difference Between Regression Testing vs Functional Testing
    Difference Between Regression Testing vs Functional Testing
    HashSet vs TreeSet In Java
    Difference Between HashSet VS LinkedHashSet VS TreeSet In Java
    ArrayList VS Vector
    Difference Between ArrayList VS Vector In Java With Example
    Hashmap vs HashSet In Java
    Difference Between HashMap VS HashSet Java
    Difference Between SDLC and STLC
    Difference Between SDLC and STLC
    Array vs ArrayList In Java
    Difference Between Array vs ArrayList in Java
    LinkedHashMap In Java
    Difference Between HashMap vs LinkedHashMap In Java Detail
    Difference Between Agile Model and V Model
    Difference Between Agile Model and V Model
    Checked Exception VS Unchecked Exception In Java
    Checked Exception VS Unchecked Exception In Java

    Filed Under: Difference

    Reader Interactions

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    Primary Sidebar

    Join SoftwareTestingo Telegram Group

    Categories

    Footer

    Java Tutorial for Beginners | Selenium Tutorial | Manual Testing Tutorial | SQL Tutorial For Beginners | GitHub Tutorial For Beginners | Maven Tutorial

    Copyright © 2023 SoftwareTestingo.com ~ Contact Us ~ Sitemap ~ Privacy Policy ~ Testing Careers