public static final String trimEnd(String str){
  int position=str.length();
  while ((position > 0) && Character.isWhitespace(str.charAt(position - 1))) {
    position--;
  }
  return str.substring(0,position);
}

public static final String trimEnd ( String str ) { int position = str . length ( ) ; while ( ( position > 0 ) && Character . isWhitespace ( str . charAt ( position - 1 ) ) ) { position -- ; } return str . substring ( 0 , position ) ; }
returns str with any terminating whitespace removed .
