Is there a convenience method to initialize a Set equivalent to Collections.singleton, which returns a mutable Set instead of an immutable one?
Asked
Active
Viewed 9,046 times
7
Rian Schmits
- 3,018
- 2
- 27
- 43
2 Answers
11
Guava is defintely a good solution.
Alternatively, you can do:
Set<T> mySet = new HashSet<>(Arrays.asList(t1, t2, t3));
Jean Logeart
- 50,693
- 11
- 81
- 116