Count number of each char in a String
Oh woah! xD It's just.. woah! What patience you have to write all those variables.

Well, it's Java so you can use a HashMap.

Write something like this:

String str = "Hello World";
int len = str.length();
Map&lt;Character, Integer&gt; numChars = new HashMap&lt;Character, Integer&gt;(Math.min(len, 26));

for (int i = 0; i &lt; len; ++i)
{
    char charAt = str.charAt(i);

    if (!numChars.containsKey(charAt))
    {
        numChars.put(charAt, 1);
    }
    else
    {
        numChars.put(charAt, numChars.get(charAt) + 1);
    }
}

System.out.println(numChars);



We do a for loop over all the string's characters and save the current char in the charAt variable
We check if our HashMap already has a charAt key inside it


If it's true we will just get the current value and add one.. this means the string has already been found to have this char.
If it's false (i.e. we never found a char like this in the string), we add a key with value 1 because we found a new char

Stop! Our HashMap will contain all chars (keys) found and how many times it's repeated (values)!