Skip to main content

Set

java.util.Set INTERFACE

caution
  • Set does not maintain any particular order
  • Set cannot be called by Index No. as it does not maintain any particular order
  • Unlike Java arrays or ArrayLists, Sets are not indexed. So, if we want to access the values in our Set, HashSet, TreeSet or LinkedHashSet, we need to use the iterator() method and iterate through each value. iterator() method is part of the java.util.Iterator package, so we’ll have to import the java.util.Iterator package before we can use the iterator() method.

tip

REFERENCE:~


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.

Immutable Set


HashSet


TreeSet


LinkedHashSet