Java tutorial
import java.util.Map; import java.util.TreeMap; public class Main { public static void main(String[] args) { String yourString = "UNDERSTAND"; Map<Character, Integer> count = new TreeMap<Character, Integer>(); for (char c : yourString.toCharArray()) { if (count.containsKey(c)) { count.put(c, (int) count.get(c) + 1); } else { count.put(c, 1); } } System.out.println(count); } }