I am writing an application in Android Studio that can count the occurrences of each letter of a sentence. Ex:
// Input
String sentence = "abbdddd";
// Output
a:1; b:2; c:0; d:4; e:0; f:0; // And so on
However, I also want it to count Amharic characters, so if I put in:
String sentence = "abcሀሁሂ";
It would give me:
a:1; b:1; c:1 ... ሀ:1; ሁ:1; ሂ:1;
At the moment, I have two ArrayLists, cycle and letterCount. Cycle has all the possible characters any letter of the inputted sentence could be. letterCount is the same size as cycle, and at runtime, every value is equal to zero. When you type in a sentence, it looks for any matches in cycle (which, if the letter is english or amharic, it should find). When it finds a match, it goes to letterCount and adds one to the corresponding value. So if the first letter in the sentence is "a", then it goes to the first value of letterCount and adds one. If it is "c", then it goes to the third value of letterCount and adds one. The values inside cycle and letterCount are added dynamically using a for loop:
for (int i = 97; i < 123; i++) {
char val = (char)i; // This is where the problem lies...I think
cycle.add(val);
letterCount.add(0);
}
However, doing "(char)i" converts it to an ASCII character, which doesn't include Amharic characters. So is there a way to, instead of looping through ASCII, loop through unicode characters and add them to cycle? Any help would be greatly appreciated.