java 去掉字符串右侧空格

public static String rightTrim(String str) {
    String regex = "(.*\S+)(\s+$)";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(str);
    if (m.matches()) {
       str = m.group(1);
    }
  return str;
 }

原文地址:https://www.cnblogs.com/101key/p/3195446.html