I have that method :
public void checkCategories(Integer... indices) {
.....
}
and the input of this method is lists of Integer lists.
My question is how to convert the lists of Integer lists to Integer arrays be passed in that method ?
You can convert List to array by method toArray()
List<Integer> integerList = new ArrayList<Integer>();
Integer[] flattened = new Integer[integerList.size()];
integerList.toArray(flattened);
checkCategories(flattened);
If you need to flatten list of lists into array you can try something like that:
public static void main(String [] args) {
List<List<Integer>> integers = Lists.newArrayList(
Lists.newArrayList(1, 2, 3, 4),
Lists.newArrayList(5, 3, 6, 7)
);
Integer[] flattened = integers.stream()
.flatMap(Collection::stream)
.toArray(Integer[]::new);
checkCategories(flattened);
}
public static void checkCategories(Integer... indices) {
for (Integer i : indices) {
System.out.println(i);
}
}
It prints:
1
2
3
4
5
3
6
7
You can convert the list to an ArrayList as follows:
userList = new ArrayList<Integer>();
And then, you can convert that list to an Array using
int[] userArray = userList.toArray(new int[userList.size()]);