Quantcast
Channel: Sorting specific object of ArrayList - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Sorting specific object of ArrayList

$
0
0

I have the following ArrayList hashmap:

 [{username=p, diff=0.0}, {username=e , diff=314.0}, {username=e ,diff=90.0}, {username=p, diff=0.0}, {username=e, diff=94.0}, {username=z, diff=92.0} , {username=z, diff=102.0}  ]

Implementing code below i get the whole list sorted by "diff" key:

Collections.sort(final_itinList,                            new Comparator<HashMap<String, String>>() {                                @Override                                public int compare(HashMap<String, String> lhs,                                        HashMap<String, String> rhs) {                                                                      return Double.compare(                                            Double.parseDouble(lhs.get("diff")),                                            Double.parseDouble(rhs.get("diff")));                                }                            });

Now i have difficulties to sort the list by "diff" key only for these objects that have username different as "p". So I want for objects that have "p" username to stay at their positions and sort the others,like...

[{username=p, diff=0.0}, {username=e ,diff=90.0}, {username=e , diff=314.0},  {username=p, diff=0.0}, {username=z, diff=92.0} , {username=e, diff=94.0}, {username=z, diff=102.0}  ]

Any quick solution; Thanks in advance


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images