I encountered a code which some parts I do not understand. It has something to do with keeping count of letters in a string. I have commented the part that I do not get. I would appreciate any help. Thank you!
I tried looking it up online but none seem to answer my question.
public class test2 {
static int[] inventory;
public static final int ALPHABET = 26;
public static void main(String[] args) {
inventory = new int [ALPHABET];
String dog = "There goes the dog!";
int size = count(dog);
System.out.println(size);
}
private static int count(String data) {
data = data.toLowerCase();
int size = 0;
for (int i = 0; i < data.length(); i++) {
char ch = data.charAt(i);
if (Character.isLetter(ch)) {
size++;
inventory[ch - 'a']++; // this I don't get
}
}
return size;
}
}