How to sort HashMap by values?
HashMap<GridPane, Integer> hashmap = new HashMap<>(); Created TreeMap from LinkedHashMap, but swears on my design.
Use Collections.sort(List<T> list, Comparator<? super T> c) .
Collections.sort( list, new Comparator<Map.Entry<K, V>>() { @Override public int compare(Map.Entry<K, V> o1, Map.Entry<K, V> o2) { return (o1.getValue()).compareTo(o2.getValue()); } }); You can get the List passing to the map.getEntrySet() constructor map.getEntrySet() After you get the sorted list, add each item in turn to the Map
HasMap will not let you sort the elements inside you, because this is not an ordered collection and the location of the elements in it depends on their hashcodes. Use ThreeMap in the constructor of which you can pass a comparator that will produce a comparison of the elements. Sorting will be done by key.
Map - temqSource: https://ru.stackoverflow.com/questions/723505/
All Articles
Collections.sortaccepts an object of typeListas input, and you try to slip him aMap- temq