Sorting multiple lists by the values of another list in java -


i have 6 arraylists 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 sort them values of first list in descending order. if values in first list equals, sort 2 equal values corresponding values in second list in natural order. strings in second list can sorted in natural order calling collection.sort(second_list).

(example: because elements @ index 4 , 5 equals, have sort them elements @ index 4 , 5 in second list in natural order: 123.12 = 123.12 "2000-01-12" > "2000-01-11", order of last 2 indexes 5, 4)

the sorted lists should 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 build arraylist of strings each element in list contain elements 1 column can see above (ex: column index 0). after each element in column above concatenate string comma "," can split string after sorting (ex: "12345.12,2000-01-11,...,9". becouse sort didn't work expected, have abandoned plan.

i need kind of table allows duplicate values in rows.

maybe if first list map indexes keys , values elements in arraylists above can this:

  • i sort values of map<integer, double> values. indexes - keys, elements in first list presented - values. obtain order of indexes: 0 3 5 4 1 2
  • i sort other arraylists custom order, if values in map<integer, double> duplicates? how sort them natural order of elements in second list?

... need structure sorts fast lists mentioned.

create item object values names:

public class item {      private double value1;      private string value2;      private string value3;      private integer value4;      private integer value5;      private integer value6;      public double getvalue1() {         return value1;     }      public void setvalue1(double value1) {         this.value1 = value1;     }      public string getvalue2() {         return value2;     }      public void setvalue2(string value2) {         this.value2 = value2;     }      public string getvalue3() {         return value3;     }      public void setvalue3(string value3) {         this.value3 = value3;     }      public integer getvalue4() {         return value4;     }      public void setvalue4(integer value4) {         this.value4 = value4;     }      public integer getvalue5() {         return value5;     }      public void setvalue5(integer value5) {         this.value5 = value5;     }      public integer getvalue6() {         return value6;     }      public void setvalue6(integer value6) {         this.value6 = value6;     }          } 

and in other class use this:

public class test {      arraylist<item> items;      public test(){         items = new arraylist<>();         this.datalist();     }      public void datalist(){         item item = new item();         item.setvalue1(12345.12);         item.setvalue2("2000-01-11");         // add values         items.add(item);                       // same objects          //sort list custom comparator         collections.sort(items, new comparator<item>() {             @override             public int compare(item item1, item item2) {                 return item1.getvalue1().compareto(item2.getvalue1());             }         });              } } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -