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)
Trims trailing spaces from a string.
int n = s.length() - 1;
if (n >= 0) {
    if (s.charAt(n) != ' ') {
        return s;
    while ((--n) >= 0) {
        if (s.charAt(n) != ' ') {
            return s.substring(0, n + 1);
...
Stringrtrim(String s)
rtrim
if (s == null)
    return s;
int pos = s.length();
if (pos == 0)
    return s;
char last = s.charAt(pos - 1);
if (last > ' ')
    return s;
...
Stringrtrim(String s)
Right trims a string.
if (s == null)
    return null;
for (int k = s.length() - 1; k >= 0; k--) {
    if (!Character.isWhitespace(s.charAt(k)))
        return (k == s.length() - 1 ? s : s.substring(0, k + 1));
return "";
Stringrtrim(String s)
Trims specified string from right.
if (s == null) {
    return null;
int len = s.length();
int index = len;
while (index > 0 && Character.isWhitespace(s.charAt(index - 1))) {
    index--;
return (index <= 0) ? "" : s.substring(0, index);
Stringrtrim(String s)
Trim spaces off the right side of this string.
StringBuffer buf = new StringBuffer(s);
for (int k = buf.length() - 1; k >= 0 && buf.charAt(k) == ' '; k = buf.length() - 1) {
    buf.delete(buf.length() - 1, buf.length());
return buf.toString();
Stringrtrim(String s)
rtrim
StringBuffer buffer = new StringBuffer();
char[] chars = s.toCharArray();
for (int i = chars.length; i > 0; i--) {
    char c = s.charAt(i - 1);
    if (c != ' ') {
        buffer.append(chars, 0, i);
        break;
return buffer.toString();
Stringrtrim(String s)
rtrim
int len = s.length();
int st = 0;
char[] val = s.toCharArray();
while ((st < len) && (val[len - 1] <= ' ')) {
    len--;
return (len < s.length()) ? s.substring(st, len) : s;
StringrTrim(String s)
Elimina gli spazi a dx della stringa
if (s == null) {
    return null;
} else {
    char c[] = s.toCharArray();
    int i = s.length() - 1;
    while (i >= 0 && c[i] == ' ') {
        i--;
    return s.substring(0, i + 1);
Stringrtrim(String s, char character)
rtrim
int i = s.length() - 1;
while (i >= 0 && (s.charAt(i)) == character) {
    i--;
return s.substring(0, i + 1);
Stringrtrim(String s, char character)
rtrim
int i = s.length() - 1;
while (i >= 0 && s.charAt(i) == character) {
    i--;
return i(s, 0, i + 1);