Java Map.Entry Sorted and Max Examples

Java Map.Entry Cheat Sheet: Sorted() & Max() Made Simple ------------------------------------------------------------ MAP.ENTRY SYNTAX FOR SORTED AND MAX ----------------------------------- 1. SORTED BY KEY (ASC) map.entrySet()   .stream()   .sorted(Map.Entry.comparingByKey()) 2. SORTED BY KEY (DESC) map.entrySet()   .stream()   .sorted(Map.Entry.comparingByKey(Comparator.reverseOrder())) 3. SORTED BY VALUE (ASC) map.entrySet()   .stream()   .sorted(Map.Entry.comparingByValue()) 4. SORTED BY VALUE (DESC) map.entrySet()   .stream()   .sorted(Map.Entry.comparingByValue(Comparator.reverseOrder())) 5. MAX BY VALUE map.entrySet()   .stream()   .max(Map.Entry.comparingByValue()) 6. MIN BY VALUE map.entrySet()   .stream()   .min(Map.Entry.comparingByValue()) 7. MAX BY KEY map.entrySet()   .stream()   .max(Map.Entry.comparingByKey()) 8. MIN BY KEY map.entrySet()   .stream()   .min(Map.Entry.comparingByKey())

To view or add a comment, sign in

Explore content categories