code: private static int countSpaces(String str) {
      if (null == str) {
        return -1;
      }
      int counter = 0;
      for (int i = 0; i < str.length(); i++) {
        if (str.charAt(i) == ' ') {
          counter++;
        }
      }
      return counter;
    }
docs: Counts spaces in the string.
  
  @param str the string to process.
  @return number of spaces found.