I have an arrayList of list of String
ArrayList<List<String>> temp = new ArrayList<List<String>>();
Now, imagine we have 3 list o more like :
- list 1 : [3,8,15,98]
- list 2 : [3,4,21,98]
- list 3 : [5,4,76,90]
I would like to print only the smallest list. I mean the list which has the smallest ascending order. For example, if we take the three list abose :
- at index 0 :
item of list 1 & 2 = 3
item of list 3 = 5
3<5 so i will not print list 3
- at index 1 :
item of list1 = 8
item of list 2 = 4
4<8 so I have to print list 2
Indeed, I try to compare the items of each list at each index.
ArrayList<List<String>> temp = new ArrayList<List<String>>();
//...
//...
for(int i=0; i<temp.size()-1; i++) {
for(int j=0; j<temp.get(i).size(); j++) {
int min = Integer.valueOf(temp.get(i+1).get(j));
if(Integer.valueOf(temp.get(i).get(j)) < min) {
min = Integer.valueOf(temp.get(i).get(j));
}else if(Integer.valueOf(temp.get(i).get(j)) >=min) {
temp.get(i).remove(j);
}
}
But the method seem not be the best way. Do you have some idea ? THK