Example: Find Frequency of Character In the above program, the length of the given string, str , is found using the string method length() . We loop through each character in the string using charAt() function which takes the index ( i ) and returns the character in the given index .