In Java, how do I create a final Set that's populated at construction? I want to do something like the following:
static final Set<Integer> NECESSARY_PERMISSIONS = new HashSet<Integer>([1,2,3,6]);
but I don't know the proper syntax in Java.
When initializing static final sets I usually write it like this: public static final String[] SET_VALUES = new String[] { "a", "b" }; public static final Set<String> MY_SET = new HashSet<>(Arrays. asList(SET_VALUES));
Try this idiom:
import java.util.Arrays; new HashSet<Integer>(Arrays.asList(1, 2, 3, 6))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With