@Test public void testRtrim() { final Object[][] testParameters = new Object[][] {{"", ""}, {"hello, world ", "hello, world"}}; assertEquals("", StringUtils.rtrim(null)); for (final Object[] testParameter : testParameters) { String expected = (String) testParameter[1]; String str = (String) testParameter[0]; assertEquals(expected, StringUtils.rtrim(str)); } }
public static String rtrim(final String str) { if (str == null) { return EMPTY_STRING; } if (!hasLength(str)) { return str; } final char[] chs = str.toCharArray(); for (int i = chs.length - 1, j = chs.length; 0 < j; --i, --j) { if (!Character.isWhitespace(chs[i])) { return new String(chs, 0, j); } } return EMPTY_STRING; }
StringUtils { public static String rtrim(final String str) { if (str == null) { return EMPTY_STRING; } if (!hasLength(str)) { return str; } final char[] chs = str.toCharArray(); for (int i = chs.length - 1, j = chs.length; 0 < j; --i, --j) { if (!Character.isWhitespace(chs[i])) { return new String(chs, 0, j); } } return EMPTY_STRING; } }
StringUtils { public static String rtrim(final String str) { if (str == null) { return EMPTY_STRING; } if (!hasLength(str)) { return str; } final char[] chs = str.toCharArray(); for (int i = chs.length - 1, j = chs.length; 0 < j; --i, --j) { if (!Character.isWhitespace(chs[i])) { return new String(chs, 0, j); } } return EMPTY_STRING; }  }
StringUtils { public static String rtrim(final String str) { if (str == null) { return EMPTY_STRING; } if (!hasLength(str)) { return str; } final char[] chs = str.toCharArray(); for (int i = chs.length - 1, j = chs.length; 0 < j; --i, --j) { if (!Character.isWhitespace(chs[i])) { return new String(chs, 0, j); } } return EMPTY_STRING; }  static boolean isEmpty(final CharSequence str); static int length(final CharSequence str); static boolean hasLength(final CharSequence str); static boolean hasText(final CharSequence str); static String nvl(final String... strs); static List<String> split(final String string, final String delimiter); static String split(final String string, final String delimiter, final int index); static String ltrim(final String str); static String rtrim(final String str); static String trim(final String str); static String join(final Iterable<?> values, final String token); static String join(final Object[] values, final String token); static String multiply(final String word, final int repeat); static void multiply(final StringBuilder buffer, final String word, final int repeat); static String repeat(final String word, final int repeat); static String uncapitalize(final String str); static int countMatches(final String str, final char ch); static String removePrefix(final String str, String prefix); static String removeSuffix(final String str, String suffix); }
StringUtils { public static String rtrim(final String str) { if (str == null) { return EMPTY_STRING; } if (!hasLength(str)) { return str; } final char[] chs = str.toCharArray(); for (int i = chs.length - 1, j = chs.length; 0 < j; --i, --j) { if (!Character.isWhitespace(chs[i])) { return new String(chs, 0, j); } } return EMPTY_STRING; }  static boolean isEmpty(final CharSequence str); static int length(final CharSequence str); static boolean hasLength(final CharSequence str); static boolean hasText(final CharSequence str); static String nvl(final String... strs); static List<String> split(final String string, final String delimiter); static String split(final String string, final String delimiter, final int index); static String ltrim(final String str); static String rtrim(final String str); static String trim(final String str); static String join(final Iterable<?> values, final String token); static String join(final Object[] values, final String token); static String multiply(final String word, final int repeat); static void multiply(final StringBuilder buffer, final String word, final int repeat); static String repeat(final String word, final int repeat); static String uncapitalize(final String str); static int countMatches(final String str, final char ch); static String removePrefix(final String str, String prefix); static String removeSuffix(final String str, String suffix); static final String NULL_STRING; static final String EMPTY_STRING; }