i have a list of lists
private LinkedList<LinkedList<Double>> data =
new LinkedList<LinkedList<Double>>();
Those lists represent columns(outer list) and rows(inner list). Now i'd like to sort the rows by the values of column 0.
EDIT
New example:
row0 = [4,2]
row1 = [1,3]
After sort it should look like this.
row0 (old row1) = [1,3]
row1 (old row0) = [4,2]
I tried this: creating new Columns and adding values. data.get() indexes a column data.get().get() indexes a row
for (int i = 0; i < 2; i++) {
LinkedList<Double> newCol = new LinkedList<Double>();
data.add(newCol);
}
data.get(0).add(4D);
data.get(0).add(1D);
data.get(1).add(2D);
data.get(1).add(3D);
To sort i wrote this code
Collections.sort(data, new Comparator<List<Double>>()
{
public int compare(List<Double> o1, List<Double> o2)
{
@Overrides
return o1.get(0).compareTo(o2.get(0));
}
});
But this code sorts the columns by the values of row0. That is not what i want.
System.out.println(data.get(0).get(0) + " " + data.get(1).get(0));
System.out.println(data.get(0).get(1) + " " + data.get(1).get(1));
The output is:
row0 = [2, 4]
row1 = [3, 1]
Anyone knows how to do this?
Comparator's code ? That seems the right way to do it, so you must have gotten wrong somewhere.