Here you can find the source of mapToString(Map
public static String mapToString(Map<Character, Integer> acs)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; public class Main { public static String mapToString(Map<Character, Integer> acs) { StringBuilder sb = new StringBuilder(); List<Character> keys = new ArrayList<Character>(acs.keySet()); Collections.sort(keys);// w w w . jav a 2s .com for (Character c : keys) { sb.append(c); int count = acs.get(c); if (count > 1) { sb.append(count); } } return sb.toString(); } }