This may be helpful to you.
I changed the type of result map to LinkedHashMap to respect insertion order.
public static void main(String[] args) {
final Map> map = new HashMap<>();
map.put("k1", Arrays.asList(new Integer[]{1, 2, 3, 4, 5}));
map.put("k2", Arrays.asList(new Integer[]{1, 2, 3, 4, 5, 6}));
map.put("k3", Arrays.asList(new Integer[]{1, 2, 3}));
System.out.println(getMapSortedByListSize(map));
}
public static Map> getMapSortedByListSize(final Map> map) {
return map.entrySet().stream()
.sorted((e1, e2) -> e1.getValue().size() - e2.getValue().size())
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (a, b) -> a, LinkedHashMap::new));
}