private boolean endsWithSpace(String str){
  return str.length() != 0 && str.charAt(str.length() - 1) == ' ';
}

private boolean endsWithSpace ( String str ) { return str . length ( ) != 0 && str . charAt ( str . length ( ) - 1 ) == ' ' ; }
checks if the string ends with a space character , false if the string is empty or ends with a non - space character
