Initialization of sets in Java
Forums:
//HashSet (first method)
HashSet<Integer> intHashSet = new HashSet<Integer>(Arrays.asList(2, 3, 5, 7, 11, 13, 17, 19));
//HashSet (second method)
intHashSet = new HashSet<Integer>() {{
add(1);
add(2);
}};
- Log in to post comments