You can write your custom Comparator
:
public class StringArrayComparator implements Comparator<String[]> {
@Override
public int compare(String[] a, String[] b) {
double aVal = Double.valueOf (a[2]) / Double.valueOf (a[1]);
double bVal = Double.valueOf (b[2]) / Double.valueOf (b[1]);
return Double.compare(aVal, bVal);
}
}
And then use it with Collections.sort
:
List<String[]> myList = /* some value */;
Collections.sort(myList, new StringArrayComparator());
Note:
This implementation assumes valid input - that all the arrays are (at least) three elements long, that the second and third elements are parsable to integers, and that the second element (which we divide by) isn't zero.