I have an array of int:
int[] a = {1, 2, 3};
I need a typed set from it:
Set<Integer> s;
If I do the following:
s = new HashSet(Arrays.asList(a));
it, of course, thinks I mean:
List<int[]>
whereas I meant:
List<Integer>
This is because int is a primitive. If I had used String, all would work:
Set<String> s = new HashSet<String>( Arrays.asList(new String[] { "1", "2", "3" }));
A) int[] a...
to
B) Integer[] a ...
Thanks!
Using Stream:
// int[] nums = {1,2,3,4,5} Set<Integer> set = Arrays.stream(nums).boxed().collect(Collectors.toSet())
1.4m articles
1.4m replys
5 comments
57.0k users