How to count all alphabetical characters in array? <p>So basically my objective is to make a program that takes the user input and reverses it and prints the inverse character back to user as an encoded message. Right now i need to print the statistics of the user entered string. How do i count the amount of occurrences of different letters from the user string. I have this so far.</p> <pre><code> import java.util.*; public class SecretCodeMachine { public static void main(String[]args) { //object accessing the non static methods SecretCodeMachine a = new SecretCodeMachine(); //input stream Scanner in = new Scanner (System.in); Scanner i = new Scanner (System.in); //prompt the user System.out.println("Please input your secret message."); String input = in.nextLine(); //calls the encodedMessage() method; equals the return value to varaible String encodedMessage = a.encodeMessage(input); //message and prompt System.out.println("Encoded message: " + encodedMessage); System.out.println("Enter the code in here to get the original message back."); String input2 = i.nextLine(); //if statements saying that if the input equals the encoed message... if (input2.equals(encodedMessage)) { //print this System.out.println("Original Message: " + input); } else { //prints when doesnt equal System.out.println("Message not found."); } //closes the input stream i.close(); in.close(); } //method for encoding the string from array public String encodeMessage(String pass) { //passes the parameter string and puts it in an array () char[] toArray = pass.toCharArray(); for (int i = 0; i &lt; toArray.length; i++) { //does the lower case characters if (toArray[i] &gt;= 'a' &amp;&amp; toArray[i] &lt;= 'z') { if (toArray[i] - 'a' &lt;= 13) toArray[i] = (char) ('z' - (toArray[i] - 'a')); else toArray[i] = (char) ('a' + ('z' - toArray[i])); } //does the upper case characters else if(toArray[i] &gt;= 'A' &amp;&amp; toArray[i] &lt;= 'Z') { if (toArray[i] - 'A' &lt;= 13) toArray[i] = (char) ('Z' - (toArray[i] - 'A')); else toArray[i] = (char) ('A' + ('Z' - toArray[i])); } //if the characters are non alphatbetic else { toArray[i] = toArray[i]; } } //converts the toArray back to new string String encodedMessage = new String(toArray); //returns the encodedMessage string return encodedMessage; } </code></pre> <p>}</p> <p>So how would i keep a track off all the letters that are entered by the user?</p>