// "Replace with 'Entry.comparingByKey()'" "true-preview"

import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

class X {
  private static List<Map.Entry<String, Integer>> sortFrequencies(Map<String, Integer> freq) {
    return freq.entrySet().stream()
      .sorted(Comparator.<Map.Entry<String, Integer>, String><caret>comparing(Map.Entry::getKey).thenComparing(Map.Entry::getValue))
      .collect(Collectors.toList());
  }
}