code: public static <K, V> Map<K, V> sort(Map<K, V> map,
              Comparator<K> comparator) {
          TreeMap<K, V> sortedMap = new TreeMap<>(comparator);
          sortedMap.putAll(map);
          return sortedMap;
      }
docs: Sort map.
  
  @param <K>        the type parameter
  @param <V>        the type parameter
  @param map        the map
  @param comparator the comparator
  @return the map