Java Utililty Methods String Trim Right

List of utility methods to do String Trim Right

Description

The list of methods to do String Trim Right are organized into topic(s).

Method

Stringrtrim(final String text)
rtrim
return rtrim(text, null);
StringrTrim(final String value)
Removes empty space from the end of a string
if (value == null) {
    return null;
String trimmed = value;
int offset = value.length() - 1;
while (offset > -1 && (value.charAt(offset) == ' ' || value.charAt(offset) == '\t')) {
    offset--;
if (offset < value.length() - 1) {
    trimmed = value.substring(0, offset + 1);
return trimmed;
Stringrtrim(String input)
Remove trailing spaces from input.
if (input == null) {
    return null;
int i = 0;
for (i = input.length() - 1; i >= 0 && Character.isWhitespace(input.charAt(i)); i--) {
    ;
return input.substring(0, i + 1);
...
StringrTrim(String orgStr, String delimiter)
Right Trim the empty space before the delimiter presents in the string
try {
    int index = orgStr.indexOf(delimiter);
    orgStr = ((orgStr.substring(0, index)).trim().length() > 0) ? orgStr : orgStr.substring(index);
    return orgStr;
} catch (Throwable th) {
    return orgStr;
Stringrtrim(String orig)

Trim the whitespace off the right side of a String.

int len = orig.length();
int st = 0;
int off = 0;
char[] val = orig.toCharArray();
while ((st < len) && (val[off + len - 1] <= ' ')) {
    len--;
return ((st > 0) || (len < orig.length())) ? orig.substring(st, len) : orig;
...
Stringrtrim(String pString)
Trims the argument string for whitespace on the right side only.
if ((pString == null) || (pString.length() == 0)) {
    return pString;
for (int i = pString.length(); i > 0; i--) {
    if (!Character.isWhitespace(pString.charAt(i - 1))) {
        if (i == pString.length()) {
            return pString;
        } else {
...
Stringrtrim(String s)
Trims the space characters from the end of a string.
int count = s.length();
int len = count;
while ((0 < len) && isSpace(s.charAt(len - 1))) {
    len--;
return (len < count) ? s.substring(0, len) : s;
Stringrtrim(String s)
Removes space, carriage, linefeed, and tab chars at the right side of a string.
int index = s.length() - 1;
while (index >= 0 && (s.charAt(index) == ' ' || s.charAt(index) == '\n' || s.charAt(index) == '\r'
        || s.charAt(index) == '\t')) {
    index--;
return (s.substring(0, index + 1));
Stringrtrim(String s)
Remove all trailing blanks.
int index = s.length() - 1;
while (index >= 0 && isSpace(s.charAt(index)))
    index--;
return s.substring(0, index + 1);
StringrTrim(String s)
Purpose:
rTrim

int i = s.length() - 1;
while (i >= 0 && Character.isWhitespace(s.charAt(i))) {
    i--;
return s.substring(0, i + 1);