Set
java.util.Set INTERFACE
caution
Setdoes not maintain any particular orderSetcannot be called byIndex No.as it does not maintain any particular order- Unlike Java
arraysorArrayLists,Setsare not indexed. So, if we want to access the values in ourSet,HashSet,TreeSetorLinkedHashSet, we need to use the iterator() method and iterate through each value.iterator()method is part of thejava.util.Iteratorpackage, so we’ll have to import thejava.util.Iteratorpackage before we can use theiterator()method.
tip
REFERENCE:~
- Official Documentation:-
Java 14java.util.Sethttps://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/Set.html - ...
info
Setis a collection that contains no duplicate elements.- When you need to keep only unique elements within a collection, to get rid of duplicates in a sequence, or if you intend to perform some mathematical operations, you may use a
set. - A
setis a collection of unique elements like a mathematical set. A set is significantly different from an array or a list since it's impossible to get an element by its index.