Here is what I have -
How can I match multiple keys and their values? I am using employeeId right now, but I would like to include departmentId and others in my comparison for sorting ...
import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.List; public class Tester { boolean flag = false ; public static void main(String args[]) { Tester tester = new Tester() ; tester.printValues() ; } public void printValues () { List<HashMap<String,Object>> list = new ArrayList<HashMap<String,Object>>() ; HashMap<String,Object> map = new HashMap<String,Object>(); map = new HashMap<String,Object>(); map.put("employeeId", new Integer(1234)) ; map.put("departmentId", new Integer(110)) ; map.put("someFlag", "B") ; map.put("eventTypeId", new Integer(11)) ; map.put("startDate", new Date() ) ; map.put("endDate", new Date() ) ; list.add(map); map = new HashMap<String,Object>(); map.put("employeeId", new Integer(456)) ; map.put("departmentId", new Integer(100)) ; map.put("someFlag", "B") ; map.put("eventTypeId", new Integer(11)) ; map.put("startDate", new Date() ) ; map.put("endDate", new Date() ) ; list.add(map); map = new HashMap<String,Object>(); map.put("employeeId", new Integer(1234)) ; map.put("departmentId", new Integer(10)) ; map.put("someFlag", "B") ; map.put("eventTypeId", new Integer(17)) ; map.put("startDate", new Date() ) ; map.put("endDate", new Date() ) ; list.add(map); map = new HashMap<String,Object>(); map.put("employeeId", new Integer(1234)) ; map.put("departmentId", new Integer(99)) ; map.put("someFlag", "B") ; map.put("eventTypeId", new Integer(11)) ; map.put("startDate", new Date() ) ; map.put("endDate", new Date() ) ; list.add(map); map = new HashMap<String,Object>(); map.put("employeeId", new Integer(1234)) ; map.put("departmentId", new Integer(100)) ; map.put("someFlag", "B") ; map.put("eventTypeId", new Integer(11)) ; map.put("startDate", new Date() ) ; map.put("endDate", new Date() ) ; list.add(map); map = new HashMap<String,Object>(); map.put("employeeId", new Integer(567)) ; map.put("departmentId", new Integer(200)) ; map.put("someFlag", "P") ; map.put("eventTypeId", new Integer(12)) ; map.put("startDate", new Date() ) ; map.put("endDate", new Date() ) ; list.add(map); Collections.sort ( list , new HashMapComparator2 () ) ; for( int i = 0 ; i < list.size() ; i ++ ) { System.out.println(list.get(i)); } System.out.println("======================================"); flag = true ;