which of the below if more efficient and why
- Looping through a list and checking the greatest and summing into a integer
public List<Integer> returnComparision(List<Integer> a, List<Integer> b){
List<Integer> resultLoop = null;
int aResult = 0;
int bResult=0;
for(int i=0; i <a.size() ; i++){
if(a.get(0) > b.get(0)){
aResult += 1;
}
else {
bResult += 1;
}
}
resultLoop.add(aResult);
resultLoop.add(bResult);
return resultLoop;
}
or using ternary to push the total into List
public List<Integer> returnComparision(List<Integer> a, List<Integer> b){
List<Integer> result = null;
result.add( ((a.get(0) > b.get(0)?1:0) + ((a.get(1) > b.get(1))?1:0)) + ((a.get(2) > b.get(2))?1:0) );
result.add( ((b.get(0) > a.get(0)?1:0) + ((b.get(1) > a.get(1))?1:0)) + ((b.get(2) > a.get(2))?1:0) );
return result;
}