If I call forEach function for a list created as
Collection.singletonList
or Arrays.asList
,
the required parameter for the function accept for the Consumer required in the forEach
function as parameter is type of int[](for new int[]{})
or Interger[](for new Integer[]{})
It seems like every element of the array is passed like an array of size one. So when I'm printing the value like Arrays.toString(x)
where type of x
is int[]
, it's working fine
Collections.singletonList(new int[] {1, 2, 3})
.forEach(new Consumer<int[]>() {
@Override
public void accept(int[] o) {
System.out.println(o);
}
});
Why the required parameter is of type int[]
instead of int