Alternative to Nested Loop For Comparison
- by KGVT
I'm currently writing a program that needs to compare each file in an ArrayList of variable size. Right now, the way I'm doing this is through a nested code loop:
if(tempList.size()>1){
for(int i=0;i<=tempList.size()-1;i++)
//Nested loops. I should feel dirty?
for(int j=i+1;j<=tempList.size()-1;j++){
//*Gets sorted.
System.out.println(checkBytes(tempList.get(i), tempList.get(j)));
}
}
I've read a few differing opinions on the necessity of nested loops, and I was wondering if anyone had a more efficient alternative.
At a glance, each comparison is going to need to be done, either way, so the performance should be fairly steady, but I'm moderately convinced there's a cleaner way to do this. Any pointers?