Here you can find the source of rtrim(String s)
Parameter | Description |
---|---|
s | the string to edit |
public static final String rtrim(String s)
//package com.java2s; public class Main { /**/*from ww w . ja va 2 s.c om*/ * Trims the space characters from the end of a string. * For example, the call <CODE>rtrim ("Tennessee", 'e')</CODE> * returns the string "Tenness".<BR> * All characters that have codes less than or equal to * <code>'\u0020'</code> (the space character) are considered to be * white space. * @param s the string to edit * @return the trimmed string */ public static final String rtrim(String s) { int count = s.length(); int len = count; while ((0 < len) && isSpace(s.charAt(len - 1))) { len--; } return (len < count) ? s.substring(0, len) : s; } public static final boolean isSpace(String s) { if (s != null) { int len = s.length(); for (int i = 0; i < len; i++) { char c = s.charAt(i); if (c != ' ' && c != '\t' && c != '\n' && c != '\r') { return false; } } } return true; } private static boolean isSpace(char c) { return c <= ' '; } }