Whoa this is a lot simpler than the method I had found, though slightly less flexible. I think I'll use this way of sorting on multiple fields in the future for a lot of 'one-time' sorting jobs where I don't necessarily need to sort the data in a lot of different ways.
Excellent explanation. Adding to your video.. we can do something like below in java8 with multiple fields: listOfEmps.stream().sorted(Comparator.comparing(Employee::getEmpId).thenComparing(Employee::getEmpName)).forEach(System.out::println);
Thanks for video/ I have an issue with this way of sorting though. Because, when the first field is sorted , second one is ignored/ For ex suppose there are two fields Age and name , & i intend to sort on age and name both. So if there are two entries with age 34, and name as Abhi and Nutan, I need Abhi to appear first in the list and then Nutan. How do I achieve this?
Hi , Hashmap have a key as orgid and value as emplist Ex: Map Employee class have empid ,empsalary Need to sort the hash map based on emp salary ??? Is it possible .. can u please explain the same with code .. Thanks, Karthic Sakthivel