Here you can find the source of rtrim(final String str)
public static String rtrim(final String str)
//package com.java2s; //License from project: Open Source License public class Main { public static String rtrim(final String str) { int i, j; for (i = str.length() - 1; i >= 0; i--) { char ch = str.charAt(i); if (ch != ' ') { break; }/* ww w .j a va 2s . co m*/ } char[] res = new char[i + 1]; for (j = 0; j <= i; j++) { res[j] = str.charAt(j); } return new String(res, 0, i + 1); } }