code: public static String trimRight(String string) {
          int i = string.length()-1;
          while (i >= 0 && Character.isWhitespace(string.charAt(i))) {
              i--;
          }
          return string.substring(0,i+1);
      }
docs: Trims {@link Character#isWhitespace(char) whitespace} characters from the
  end of specified <code>string</code>
  @param string String to trim
  @return new String without the whitespace at the end