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 s, Character c)
rtrim
if (s == null) {
    return null;
if (c == null) {
    return s;
int len = s.length();
int st = 0;
...
Stringrtrim(String source)
rtrim
return source.replaceAll("\\s+$", "");
Stringrtrim(String source)
remove trailing whitespace
return source.replaceAll("\\s+$", "");
Stringrtrim(String src, char ch, int nLen)
rtrim
if (src == null || src.length() <= nLen)
    return src;
char[] czSrc = src.toCharArray();
int i, j;
int n = czSrc.length;
for (i = n - 1; i >= nLen; i--) {
    if (czSrc[i] != ch)
        break;
...
Stringrtrim(String str)
rtrim
int i = str.length();
while (i > 0) {
    switch (str.charAt(i - 1)) {
    case ' ':
    case '\t':
        i--;
        continue;
    break;
return str.substring(0, i);
Stringrtrim(String str)
rtrim
if (!hasLength(str)) {
    return str;
StringBuilder sb = new StringBuilder(str);
while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
    sb.deleteCharAt(sb.length() - 1);
return sb.toString();
...
Stringrtrim(String str)
rtrim
int start = str.length() - 1;
for (int i = start; i >= 0; i--) {
    char c = str.charAt(i);
    if (c != ' ' && c != '\t') {
        return i != start ? str.substring(0, i + 1) : str;
return "";
...
Stringrtrim(String str)
rtrim
return rtrim(str, " ");
Stringrtrim(String str)
rtrim
int index = str.length();
while (' ' == str.charAt(--index))
    ;
if (index < str.length())
    str = str.substring(0, index + 1);
return str;
StringrTrim(String str)
r Trim
return trimAt(str.length(), str);