pcyuen98 / covidAngular

0 stars 0 forks source link

KT --> The Difference Between a Set and an Array List in Java #30

Open uyunAkmal opened 3 years ago

uyunAkmal commented 3 years ago

Set (an interface) – Set implementations: HashSet, LinkedHashSet, TreeSet etc. • Unorder collection, there are few implementations of Set which maintains the order such as LinkedHashSet (It maintains the elements in insertion order). • Set doesn’t allow duplicate elements. All the elements of a Set should be unique if you try to insert the duplicate element in Set it would replace the existing value. • Set can have only a single null value at most. • Cannot be access by index List implements: LinkedList, Arraylist
• Java ArrayList class maintains insertion order • Java ArrayList class can contain duplicate elements • resizable-array implementation of the List interface. It implements all optional list operations, and permits all elements, including null-allow any number • Java ArrayList class is non synchronized. • Java ArrayList allows random access because array works at the index basis. When to use SET / ARRAYLIST • set is the best implementation when the requirement is to have only the unique value • list is use when need to maintain the insertion order irrespective of the duplicity Reference: https://www.tutorialspoint.com/difference-between-arraylist-and-hashset-in-java https://beginnersbook.com/2014/07/difference-between-list-and-set-in-java/ https://stackoverflow.com/questions/1035008/what-is-the-difference-between-set-and-list https://www.javatpoint.com/java-arraylist