I am coding in java and i have three arrays also i have a List of lists.
int[] recovery=bl.generateRecovery();
int[] periods = bl.generatePeriods(recovery);
int[] deadlines = bl.generateDeadlines(periods);
List<List<Integer>>temp=new ArrayList<List<Integer>>();
Now i want to add the arrays as lists in the list.
I tried using:
temp.add(Arrays.asList(recovery));
But it failed. Can someone tell me how to do it ??
You can make use of Arrays.stream on int[] boxed and collected as List as:
temp.add(Arrays.stream(recovery).boxed().collect(Collectors.toList()));
Arrays.asList(recovery) will give you a List<int[]> object, not List<Integer>. Try using Integer[] recovery instead.
Edit:
You might want to have your methods like generateRecovery etc. to return List<Integer> instead of int[]. Arrays are not flexible and it is usually better to use List.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With