Java Language Collection Factory Methods Set Factory Method Examples

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


  • Set<Integer> immutableEmptySet = Set.of();
    • Initializes an empty, immutable Set<Integer>.
  • Set<Integer> immutableSet = Set.of(1, 2, 3, 4, 5);
    • Initializes an immutable Set<Integer> with five initial elements.
  • Set<Integer> mutableSet = new HashSet<>(immutableSet);
    • Initializes a mutable Set<Integer> from an immutable Set<Integer>.

Got any Java Language Question?