I am using the following code to traverse through a array of arraylist:
for(List<Long> innerList : arr) {
for(Long number : innerList) {
System.out.println(number);
}
}
This code returns the number in each array of the arraylist.I want to compare the first element of the first array of the arraylist with all other elements of all other array of the arraylist. How to do this?
Complete program:
static long getWays(long sum, long[] changes) {
int count=0;
ArrayList<ArrayList<Long>> arr = new ArrayList<ArrayList<Long>>();
for(int i=0;i<changes.length;i++){
ArrayList<Long> arr1 = new ArrayList<Long>();
long change = changes[i];
long value = changes[i];
arr1.add(change);
for(int j=0;j<sum;j++){
change = change + value;
if(change>sum){
break;
}
arr1.add(change);
}
arr.add(arr1);
}
for(List<Long> innerList : arr) {
for(Long number : innerList) {
System.out.println(number);
}
}
return count;
}