Since I'm just starting with JAVA, I'm curious what is the best option for implementing sorting in JAVA (for ArrayLists). Below I provide my PHP code.
public int cmp($a, $b) {
if ( $a[0] < $b[0] ) return 1;
else if ( $a[0] > $b[0] ) return -1;
else if ( $a[1] < $b[1] ) return 1;
else if ( $a[1] > $b[1] ) return -1;
else return 0;
}
$selected = array();
for ($i=0; $i<$len; $i++) {
$rank = getRank();
$cub = getCub_len();
$selected[] = array($rank,$cub);
}
uasort($selected, 'cmp')
Well, I wrote the following code in JAVA:
ArrayList<ArrayList<Double>> selected = new ArrayList<ArrayList<Double>>();
ArrayList<Double> rank = new ArrayList<Double>();
ArrayList<Double> cub = new ArrayList<Double>();
for (int i=0; i<len; i++) {
rank.add(getRank(i));
cub.add(getCub(i));
}
selected.add(0,rank);
selected.add(1,cub);
How to sort selected
in the proper way (similarly to PHP function cmp
)?