How to sort map on the basis of time field in object. My Map looks like:
Map<Integer, ShiftDTO> -> ShiftDTO
consist of following key: shiftName
, shiftStartTime
, shiftEndTime
. shiftStartTime
is of type Date
, and I want to sort on the basis of date in ascending order. Following code I was using to sort on the basis of map key:
LinkedHashMap<Integer, ShiftDTO> sortedMap = new LinkedHashMap<Integer, ShiftDTO>();
v.getShiftHashMap().entrySet().stream().sorted(Map.Entry.comparingByKey())
.forEachOrdered(x -> sortedMap.put(x.getKey(), x.getValue()));
But how can I sort all shift entries on the basis of shiftStartTime
?