count[str1.charAt(i)]
charAt() returns char type. How can char type be used as index in array
YES! It is possible. It is a basic rule of java. We can assign char value to int type of variable. Now that int type variable will not store a character but its ASCII value. See the example
class Test{
public static void main(String[] args){
int num='a';
System.out.println(num);//97
}
}
you can see i've assigned 'a' into int type of variable.
In same case, whenever we pass char as index value, always ASCII value will be passed. As we know, 97 is the ASCII value of a.
So if we access an array by passing 'a', internally 97th index of array will be called.
int num='a';
System.out.println(args[num]);//AIOOBE
Here we got Exception like
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 97 at Test.main(Test.java:4)
Program is compiled fine, but we got exception at runtime because args is empty array right now.
char value is not an ASCII value, but rather "A char value [...] represents Basic Multilingual Plane (BMP) code points, including the surrogate code points, or code units of the UTF-16 encoding. " -- docs.oracle.com/javase/9/docs/api/java/lang/Character.html
charis an integral type. Yes, that is legal.