0

I want to sort my array list based on one specific value in the the same arraylist. for example,

List<String>status=new ArrayList<String>();
status.add("COMPLETED");
status.add("COMPLETED");
status.add("TODO");
status.add("INPROGRESS");
status.add("COMPLETED");

Here i want to move elements which contains 'COMPLETED' to end of the arraylist..

for example, it should display like below.. just need to move the first two elements(0,1) into after the current last index(4).

TODO
INPROGRESS
COMPLETED
COMPLETED
COMPLETED
Saravanan
  • 11,372
  • 43
  • 143
  • 213
  • Please explain if this is not a duplicate. Since this is a similar question you've asked earlier in the day as well. If there is something that's still not solved, maybe it's worth re-opening. – Naman Jan 17 '19 at 14:37
  • `Collections.sort(status, (a,b)-> b.equals("COMPLETED") ? -1 :1);` – Ryuzaki L Jan 17 '19 at 14:39

1 Answers1

0

You can sort them using a Comparator and then print them out. Like this

status.stream()
          .sorted(Comparator.comparing(x -> x.equals("COMPLETED")))
          .forEachOrdered(System.out::println);
Kirby
  • 15,127
  • 10
  • 89
  • 104
Eugene
  • 117,005
  • 15
  • 201
  • 306
  • (genuinely) Please reopen(since you can), if you think this is not a duplicate. I am still 7:3 confident of this being a duplicate, maybe because the question is not very well based on a use-case. – Naman Jan 17 '19 at 14:40