Here you can find the source of rtrim(String str, String defaultValue)
Parameter | Description |
---|---|
str | String to clean |
public static String rtrim(String str, String defaultValue)
//package com.java2s; //License from project: LGPL public class Main { /** //ww w. j ava2s . c om * This function returns a string with whitespace stripped from the end of str * @param str String to clean * @return cleaned String */ public static String rtrim(String str, String defaultValue) { if (str == null) return defaultValue; int len = str.length(); while ((0 < len) && (str.charAt(len - 1) <= ' ')) { len--; } return (len < str.length()) ? str.substring(0, len) : str; } public static int length(String str) { if (str == null) return 0; return str.length(); } /** * this method works different from the regular substring method, the regular substring method takes startIndex and endIndex as second and third argument, * this method takes offset and length * @param str * @param off * @param len * @return */ public static String substring(String str, int off, int len) { return str.substring(off, off + len); } }