Set
java.util.Set
INTERFACE
caution
Set
does not maintain any particular orderSet
cannot be called byIndex No.
as it does not maintain any particular order- Unlike Java
arrays
orArrayLists
,Sets
are not indexed. So, if we want to access the values in ourSet
,HashSet
,TreeSet
orLinkedHashSet
, we need to use the iterator() method and iterate through each value.iterator()
method is part of thejava.util.Iterator
package, so we’ll have to import thejava.util.Iterator
package before we can use theiterator()
method.
tip
REFERENCE:~
- Official Documentation:-
Java 14
java.util.Set
https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/util/Set.html - ...
info
Set
is 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
set
is 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.