@Test public void testSortByValueRu() { Map<String, String> sorted = MapUtil.sortByValue(ru_map); Map.Entry<String, String> entry = sorted.entrySet().iterator().next(); String value = entry.getValue(); Assert.assertTrue(value.equals("Азеррбайджан")); }
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); List<Map.Entry<K, V>> sorted = Stream.of(list).sortBy(Map.Entry::getValue).toList(); Map<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : sorted) { result.put(entry.getKey(), entry.getValue()); } return result; }
MapUtil { public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); List<Map.Entry<K, V>> sorted = Stream.of(list).sortBy(Map.Entry::getValue).toList(); Map<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : sorted) { result.put(entry.getKey(), entry.getValue()); } return result; } }
MapUtil { public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); List<Map.Entry<K, V>> sorted = Stream.of(list).sortBy(Map.Entry::getValue).toList(); Map<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : sorted) { result.put(entry.getKey(), entry.getValue()); } return result; }  }
MapUtil { public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); List<Map.Entry<K, V>> sorted = Stream.of(list).sortBy(Map.Entry::getValue).toList(); Map<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : sorted) { result.put(entry.getKey(), entry.getValue()); } return result; }  static Map<K, V> sortByValue(Map<K, V> map); }
MapUtil { public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) { List<Map.Entry<K, V>> list = new ArrayList<>(map.entrySet()); List<Map.Entry<K, V>> sorted = Stream.of(list).sortBy(Map.Entry::getValue).toList(); Map<K, V> result = new LinkedHashMap<>(); for (Map.Entry<K, V> entry : sorted) { result.put(entry.getKey(), entry.getValue()); } return result; }  static Map<K, V> sortByValue(Map<K, V> map);  }