code: public static <T extends Comparable<T>> String toSortedByKeysString(Counter<T> counter, String itemFormat, String joiner, String wrapperFormat) {
      List<String> strings = new ArrayList<String>();
      for (T key : CollectionUtils.sorted(counter.keySet())) {
        strings.add(String.format(itemFormat, key, counter.getCount(key)));
      }
      return String.format(wrapperFormat, StringUtils.join(strings, joiner));
    }
docs: Returns a string representation of a Counter, where (key, value) pairs are
  sorted by key, and formatted as specified.
  
  @param counter
  The Counter.
  @param itemFormat
  The format string for key/count pairs, where the key is first and
  the value is second. To display the value first, use argument
  indices, e.g. "%2$f %1$s".
  @param joiner
  The string used between pairs of key/value strings.
  @param wrapperFormat
  The format string for wrapping text around the joined items, where
  the joined item string value is "%s".
  @return The Counter, formatted as specified.