1 package org.djutils.immutablecollections;
2
3 import java.util.HashSet;
4
5
6
7
8
9 public final class ImmutableCollectionsDemo
10 {
11
12
13
14 private ImmutableCollectionsDemo()
15 {
16
17 }
18
19
20
21
22
23 public static void main(final String[] args)
24 {
25 HashSet<String> hashSet = new HashSet<>();
26 hashSet.add("String 1");
27 hashSet.add("String 2");
28 System.out.println("normal hash set contains: " + hashSet);
29 ImmutableHashSet<String> immutableHashSetWithCopy = new ImmutableHashSet<>(hashSet);
30 ImmutableHashSet<String> immutablehashSetThatWraps = new ImmutableHashSet<>(hashSet, Immutable.WRAP);
31 System.out.println("immutable hash set with copy: " + immutableHashSetWithCopy);
32 System.out.println("immutable hash set that wraps: " + immutablehashSetThatWraps);
33 hashSet.add("String 3");
34 System.out.println("immutable hash set with copy: " + immutableHashSetWithCopy);
35 System.out.println("immutable hash set that wraps: " + immutablehashSetThatWraps);
36 ImmutableIterator<String> immutableIterator = immutableHashSetWithCopy.iterator();
37 while (immutableIterator.hasNext())
38 {
39 String string = immutableIterator.next();
40 System.out.println("string is " + string);
41 immutableIterator.remove();
42 }
43
44
45
46
47 }
48
49 }