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) { return trimAt(str.length(), str); }//from w w w .j av a2 s. c o m public static String trimAt(int index, String str) { int rightPos, leftPos; for (rightPos = index; rightPos < str.length(); rightPos++) { char c = str.charAt(rightPos); if (c == ' ' || c == '\n' || c == '\r' || c == '\t') { continue; } else { break; } } for (leftPos = index - 1; leftPos > -1; leftPos--) { char c = str.charAt(leftPos); if (c == ' ' || c == '\n' || c == '\r' || c == '\t') { continue; } else { leftPos++; break; } } return str.substring(0, leftPos) + str.substring(rightPos); } }