Here you can find the source of rightTrim(String str)
public static String rightTrim(String str)
//package com.java2s; public class Main { public static String rightTrim(String str) { 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++;//w w w. java 2s .c o m } else { break; } } return str.substring(0, len - count); } }