It would be best to create a Map to store your account. It will be Map<Character, Integer>
You need to iterate over each character of your string and check its alphabet. You can use the Character#isAlphabetic method to do this. If it's an alphabet , increase its number in Map . If the symbol is not already in the Map , then add it with a counter of 1 .
NOTE : - The Character.isAlphabetic method is new in Java 7 . If you are using an older version, you should use Character#isLetter
String str = "asdfasdfafk asd234asda"; Map<Character, Integer> charMap = new HashMap<Character, Integer>(); char[] arr = str.toCharArray(); for (char value: arr) { if (Character.isAlphabetic(value)) { if (charMap.containsKey(value)) { charMap.put(value, charMap.get(value) + 1); } else { charMap.put(value, 1); } } } System.out.println(charMap);
OUTPUT : -
{f=3, d=4, s=4, a=6, k=1}
source share