-2

I have a Map< String,ArrayList< BonusEntity > > Here key is EmpId of Employee and key will contains the List< BonusEntity >

BonusEntity will contains the following fields(All fields are String)

Empid BonusDate BonusAmount Dept

I need to sort the ArrayList in Map based on the BonusDate descending order,Can anyone help Thanks in advance.

2
  • 1
    Please improve your question quality. You can find more tips in: How do I ask a good question? and How to create a Minimal, Complete, and Verifiable example pages. Commented Jul 28, 2017 at 6:46
  • Entity class can implement Comparable implement Compare to as @Override public int compareTo(BonusEntity o) { return o.bonusdate.compareTo(this.bonusdate); } and sort list using Collections.sort(list); keep in mind that using string for holding date value will give you some unexpected results, use Date class instead of string Commented Jul 28, 2017 at 7:00

1 Answer 1

0

You should create a Comparator that applies to your class BonusEntity and use it via the Collections.sort method.

Sign up to request clarification or add additional context in comments.

2 Comments

Alternatively, have BonusEntity implement Comparable<BonusEntity> then call List.sort()
Also possible, with Comparable you'll define one natural sort for the class. You can define as many Comparator as you can need/imagine.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.