On this page
  1. Set
  2. Import
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

Set

Prev: `Map` | Up: java.util | Next: `ArrayDeque`
Rel: java.util, java/builtins
Ref: Java Docs — Set
Tags: #public #prog #java #stdlib #java_util #tier/core


Import

import java.util.*;

Signature & Overview

Set<E>  /* HashSet, LinkedHashSet, TreeSet, Set.of(...) */

Collection of unique elements ($O(1)$ lookup for HashSet, sorted $O(\log n)$ for TreeSet).

Notes & Pitfalls

Example

import java.util.Set;

Set<String> roles = Set.of("admin", "editor");
assert roles.contains("admin") && roles.size() == 2;

Linked from

Related notes