Here you can find the source of sort(Map
private static Map<Long, List<String>> sort(Map<String, Map<Long, Long>> dataNodes, boolean reverse)
//package com.java2s; //License from project: Apache License import static java.util.Collections.reverseOrder; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.TreeMap; public class Main { private static Map<Long, List<String>> sort(Map<String, Map<Long, Long>> dataNodes, boolean reverse) { Map<Long, List<String>> result = getSortedMap(reverse); for (String hostName : dataNodes.keySet()) { Map<Long, Long> usage = dataNodes.get(hostName); long space = usage.values().iterator().next(); List<String> hosts = result.get(space); if (hosts == null) { hosts = new ArrayList<>(); }// w w w. ja v a2 s.co m hosts.add(hostName); result.put(space, hosts); } return result; } private static Map<Long, List<String>> getSortedMap(boolean reverse) { if (reverse) { return new TreeMap<>(reverseOrder()); } else { return new TreeMap<>(); } } }