I have 6 ArrayLists as shown below:
index: 0 1 2 3 4 5
[12345.12 |123.0 |12.12 |1234.0 |123.12 |123.12 ] <Double>
[2000-01-11 |2000-01-11 |2000-01-11 |2000-01-12 |2000-01-12 |2000-01-11] <String>
[1234 | 1234 | 1234 | 1235 | 1235 | 1234 ] <String>
[4 | 10 | 16 | 24 | 30 | 20 ] <Integer>
[7 | 13 | 19 | 27 | 34 | 25 ] <Integer>
[9 | 15 | 21 | 29 | 35 | 40 ] <Integer>
Using Java, I want to sort them by the values of the first list in descending order. If the values in the first list are equals, then sort the two equal values by the corresponding values in the second list in natural order. The strings in the second list can be sorted in natural order by calling Collection.sort(second_list).
(Example: because the elements at index 4 and 5 are equals, I have to sort them by the elements at index 4 and 5 in the second list in natural order: 123.12 = 123.12 but "2000-01-12" > "2000-01-11", so the order of the last two indexes will be 5, 4)
The sorted lists should look like these:
0 3 5 4 1 2
[12345.12 |1234.0 |123.12 |123.12 |123.0 |12.12 ] <Double>
[2000-01-11 |2000-01-12 |2000-01-11 |2000-01-12 |2000-01-11 |2000-01-11] <String>
[1234 | 1235 | 1234 | 1235 | 1234 | 1234 ] <String>
[4 | 24 | 20 | 30 | 10 | 16 ] <Integer>
[7 | 27 | 25 | 34 | 13 | 19 ] <Integer>
[9 | 29 | 40 | 35 | 15 | 21 ] <Integer>
I have tried to build a ArrayList of strings where each element in list contain elements from one column as we can see above (ex: the column as index 0). After each element in the column above I concatenate the string with a comma "," so that I can split the string after sorting (ex: "12345.12,2000-01-11,...,9". Becouse the sort didn't work as I expected, I have abandoned this plan.
I need a kind of a table that allows duplicate values in rows.
Maybe if the first List will be a Map where indexes are keys and values are the elements in the ArrayLists above I can do this:
- I sort the values of
Map<Integer, Double>
by values. Indexes - are keys, elements in first list presented - are values. So I obtain the order of indexes: 0 3 5 4 1 2 - I sort other ArrayLists by this custom order, but what I do If the values in the
Map<Integer, Double>
are duplicates? How do I sort them by a natural order of elements in the second List?
... I need a structure that sorts fast the Lists mentioned.