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
2
  • 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. Commented Jan 17, 2019 at 14:37
  • Collections.sort(status, (a,b)-> b.equals("COMPLETED") ? -1 :1); Commented Jan 17, 2019 at 14:39

1 Answer 1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

(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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.