Have a look at this bug report which was closed as Not an Issue
citing the below reason.
Autoboxing of entire arrays is not specified behavior, for good reason. It can be prohibitively expensive for large arrays.
Therefore, to convert your array to an list, you need to do this
List<Integer> test = new ArrayList<Integer>(S.length);
for (int i : S) {
test.add(i);
}