code: public static <T> String toSortedString(Counter<T> counter, int k, String itemFormat, String joiner, String wrapperFormat) {
      PriorityQueue<T> queue = toPriorityQueue(counter);
      List<String> strings = new ArrayList<String>();
      for (int rank = 0; rank < k && !queue.isEmpty(); ++rank) {
        T key = queue.removeFirst();
        double value = counter.getCount(key);
        strings.add(String.format(itemFormat, key, value));
      }
      return String.format(wrapperFormat, StringUtils.join(strings, joiner));
    }
docs: Returns a string representation of a Counter, displaying the keys and their
  counts in decreasing order of count. At most k keys are displayed.
  
  Note that this method subsumes many of the other toString methods, e.g.:
  
  toString(c, k) and toBiggestValuesFirstString(c, k) => toSortedString(c, k,
  "%s=%f", ", ", "[%s]")
  
  toVerticalString(c, k) => toSortedString(c, k, "%2$g\t%1$s", "\n", "%s\n")
  
  @param counter
  A Counter.
  @param k
  The number of keys to include. Use Integer.MAX_VALUE to include
  all keys.
  @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 top k values from the Counter, formatted as specified.