how to test how many of one character is in a string java

Java
int count = string.length() - string.replaceAll("g","").length()
Source

Also in Java: