public static String trimTrailingSpaces(String string){
  if (string == null) {
    return null;
  }
  for (int i=string.length() - 1; i >= 0; i--) {
    if (string.charAt(i) == '\t' || string.charAt(i) == ' ' || string.charAt(i) == '\n' || string.charAt(i) == '\r') {
      continue;
    }
 else {
      string=string.substring(0,i + 1);
      return string;
    }
  }
  return string;
}

public static String trimTrailingSpaces ( String string ) { if ( string == null ) { return null ; } for ( int i = string . length ( ) - 1 ; i >= 0 ; i -- ) { if ( string . charAt ( i ) == '\t' || string . charAt ( i ) == ' ' || string . charAt ( i ) == '\n' || string . charAt ( i ) == '\r' ) { continue ; } else { string = string . substring ( 0 , i + 1 ) ; return string ; } } return string ; }
cuts the trailing \ n \ t and spaces
