Here you can find the source of rtrim(String s)
public static String rtrim(String s)
//package com.java2s; //License from project: Apache License public class Main { public static String rtrim(String s) { int len = s.length(); int st = 0; char[] val = s.toCharArray(); while ((st < len) && (val[len - 1] <= ' ')) { len--;/* w w w . ja v a 2 s . c om*/ } return (len < s.length()) ? s.substring(st, len) : s; } }