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(String str)
Right trim of a given String
int len = str.length();
char[] val = str.toCharArray();
int count = len;
while (len > 0 && (val[len - 1] <= ' ')) {
    len--;
return (len < count) ? str.substring(0, len) : str;
StringrTrim(String str)
Remove trailing whitespace of the specified string using expressions.
return str.replaceAll("\\s+$", "");
Stringrtrim(String str, String charList)
rtrim
int end = str.length() - 1;
if (null == charList)
    for (int i = end; i >= 0; i--)
        if (Character.isWhitespace(str.charAt(i)))
            end--;
        else
            break;
else
...
Stringrtrim(String str, String defaultValue)
This function returns a string with whitespace stripped from the end of str
if (str == null)
    return defaultValue;
int len = str.length();
while ((0 < len) && (str.charAt(len - 1) <= ' ')) {
    len--;
return (len < str.length()) ? str.substring(0, len) : str;
Stringrtrim(String str, String suffixs)
rtrim
if (isNull(str) || isNull(suffixs))
    return str;
int i = str.length() - 1;
for (; i >= 0; i--) {
    if (suffixs.indexOf(str.charAt(i)) == -1)
        break;
return str.substring(0, i + 1);
...
Stringrtrim(String string, String end)
rtrim
if (string.endsWith(end)) {
    string = string.substring(0, string.length() - end.length());
return string;
Stringrtrim(String text, char c)
rtrim
if (text == null) {
    return EMPTY;
int i = 0;
int j = text.length();
while ((i < j) && (text.charAt(j - 1) == c)) {
    j--;
return (j < text.length()) ? text.substring(i, j) : text;
StringrTrim(String value)
r Trim
if (value == null) {
    return null;
int index = value.length();
while (index > 0 && isWhitespace(value.charAt(index - 1))) {
    index--;
return value.substring(0, index);
...
Stringrtrim(String value, int maxLength)
rtrim
String result = nvl(value).trim();
if (result.length() > maxLength) {
    result = result.substring(0, maxLength);
return result;
StringrTrimObj(Object o)
r Trim Obj
return rTrim(nz(o));