public static int countOccurrence(String input,char c){
  if (input == null) {
    return 0;
  }
  int count=0;
  for (int i=0; i < input.length(); i++) {
    count=(input.charAt(i) == c) ? (count + 1) : count;
  }
  return count;
}

public static int countOccurrence ( String input , char c ) { if ( input == null ) { return 0 ; } int count = 0 ; for ( int i = 0 ; i < input . length ( ) ; i ++ ) { count = ( input . charAt ( i ) == c ) ? ( count + 1 ) : count ; } return count ; }
count occurrence of a character in a string
