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

StringrightTrim(final String aString)
Copies this String removing white space characters from the end of the string.
if (aString == null) {
    return null;
int end = aString.length() - 1;
while ((end >= 0) && (aString.charAt(end) <= ' ')) {
    end--;
if (end == aString.length() - 1) {
...
StringrightTrim(final String input, final char charToTrim)
Removes the occurrences of the passed char in the beggining of the string.
int len = input.length();
final int st = 0;
final int off = 0;
final char[] val = input.toCharArray();
while (st < len && val[off + len - 1] == charToTrim) {
    len--;
return input.substring(0, len);
...
StringrightTrim(String input, char charToTrim)
Removes the occurrences of the passed char in the beggining of the string.
int len = input.length();
int st = 0;
int off = 0;
char[] val = input.toCharArray();
while ((st < len) && (val[off + len - 1] == charToTrim)) {
    len--;
return input.substring(0, len);
...
StringrightTrim(String s)
right Trim
int pos = s.length();
while (--pos >= 0)
    if (!Character.isWhitespace(s.charAt(pos)))
        break;
return s.substring(0, pos + 1);
StringrightTrim(String s, char c)
right Trim
int stop;
for (stop = s.length(); stop > 0; stop--) {
    if (s.charAt(stop - 1) != c) {
        break;
if (stop > 0) {
    return s.substring(0, stop);
...
StringrightTrim(String src)
right Trim
if (src != null) {
    char[] chars = src.toCharArray();
    for (int i = chars.length - 1; i >= 0; i--) {
        if ((chars[i] != ' ') && (chars[i] != '\t') && (chars[i] != '\r')) {
            return src.substring(0, i + 1);
    return "";
...
StringrightTrim(String str)
right Trim
if (str == null)
    return str;
int len = str.length();
int count = 0;
for (int i = len - 1; i >= 0; i--) {
    if (str.charAt(i) == ' ' || str.charAt(i) == '\n' || str.charAt(i) == '\r' || str.charAt(i) == '\t') {
        count++;
    } else {
...
StringrightTrim(String str)
right Trim
if (isEmpty(str))
    return str;
char[] charArray = str.toCharArray();
int length = charArray.length;
int start = 0;
while ((start < length) && (charArray[length - 1] <= ' '))
    length--;
return str.substring(0, length);
...
StringrightTrim(String str)
Removes trailing whitespaces.
if (str.length() == 0) {
    return str;
int i = str.length() - 1;
while (i >= 0) {
    char c = str.charAt(i);
    if (Character.isWhitespace(c)) {
        i--;
...
StringrightTrim(String string)
right Trim
if (string == null) {
    return "";
return string.replaceFirst("\\s+$", "");