I was trying to convert int array to Set<Integer>.
int[] arr = {5, 2, 7, 2, 4, 7, 8, 2, 3};
Set<Integer> s = new HashSet<Integer>(Arrays.asList(arr));
But the compiler doesn't accept the above code. It says: "The constructor HashSet(List) is undefined." Well, I thought that int should be autoboxed.
I slightly modified the code, change int to String:
String[] arr = {"hello", "world"};
Set<String> s = new HashSet<String>(Arrays.asList(arr));
This code works okay.
I tried the following, change int to Integer:
Integer[] arr = {5, 2, 7, 2, 4, 7, 8, 2, 3};
Set<Integer> s = new HashSet<Integer>(Arrays.asList(arr));
This is passed the compilation.
My question is: why doesn't java compiler accept the first code?