Here you can find the source of rtrim(String str)
public static String rtrim(String str)
//package com.java2s; //License from project: Apache License public class Main { public static String rtrim(String str) { int start = str.length() - 1; for (int i = start; i >= 0; i--) { char c = str.charAt(i); if (c != ' ' && c != '\t') { return i != start ? str.substring(0, i + 1) : str; }/*from w ww . j a va 2s.co m*/ } return ""; } }