public static int rightTrimSize(String s) {

        int i = s.length();

        while (i > 0) {
            i--;

            if (s.charAt(i) != ' ') {
                return i + 1;
            }
        }

        return 0;
    }
public static int rightTrimSize ( String s ) { int i = s . length ( ) ; while ( i > 0 ) { i -- ; if ( s . charAt ( i ) != ' ' ) { return i + 1 ; } } return 0 ; }
Returns the size of substring that does not contain any trailing spaces
@param s the string
@return trimmed size