Here are some suggestions:
It seems you are just trying to get characters in a String . Use String.toCharArray() .
Use Map<Character,Integer> to store characters and their appearance:
foreach char c in sMessage.ToCharArray() if map.containsKey(c) map.put(c, map.get(c) + 1); else map.put(c, 1);
Then collect the map and present the results. I leave you a fragment for sorting the map:
List<Entry<Character,Integer>> l = new ArrayList<Entry<Character,Integer>>(map.entrySet()); Collections.sort(l, new Comparator<Entry<Character,Integer>>() { public int compare(Entry<Character, Integer> o1, Entry<Character, Integer> o2) { return o1.getKey().compareTo(o2.getKey()); } });
source share