Here you can find the source of rtrim(String str)
public static String rtrim(String str)
//package com.java2s; public class Main { public static String rtrim(String str) { return rtrim(str, " "); }//from www . j av a2s . c o m public static String rtrim(String str, String remove) { if (str == null || str.length() == 0 || remove == null || remove.length() == 0) { return str; } while (str.endsWith(remove) && (str.length() - remove.length()) >= 0) { str = str.substring(0, str.length() - remove.length()); } return str; } }