I have a complex custom object like
public class MySortedObject {
private static class Employee {
public String name;
public String ssn;
public Employee(String name, String ssn) {
super();
this.name = name;
this.ssn = ssn;
}
}
public static void main(String[] args) {
Map<Integer, List<Employee>> map = new HashMap<>();
Employee empl1 = new Employee("XYZ", "22DEC2019");
Employee empl2 = new Employee("ABC", "22DEC2019");
Employee empl3 = new Employee("GHI", "18APR2019");
Employee empl4 = new Employee("DEF", "18APR2019");
Employee empl5 = new Employee("WXY", "15OCT2019");
Employee empl6 = new Employee("JKL", "15OCT2019");
List empList1 = new ArrayList<>();
List empList2 = new ArrayList<>();
List empList3 = new ArrayList<>();
empList1.add(empl1);
empList1.add(empl2);
empList2.add(empl3);
empList2.add(empl4);
empList3.add(empl5);
empList3.add(empl6);
map.put(1, empList1);
map.put(2, empList2);
map.put(3, empList3);
}
My object is a map of <Integer,List>. The list is having objects which contain a value(i.e. ssn). I want to sort my map based on this ssn value. The order of the map should be "1,3 and 2"