Java String Trim Right rtrim(String str)

Here you can find the source of rtrim(String str)

Description

Right trim of a given String

License

Open Source License

Parameter

Parameter Description
str String to be trimmed

Return

trimmed String

Declaration

public static String rtrim(String str) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2013, Cloudsmith Inc.
 * The code, documentation and other materials contained herein have been
 * licensed under the Eclipse Public License - v 1.0 by the copyright holder
 * listed above, as the Initial Contributor under such license. The text or
 * such license is available at www.eclipse.org.
 ******************************************************************************/

public class Main {
    /**//from w w w . ja  v  a  2  s  .co m
     * Right trim of a given String
     * 
     * @param str
     *            String to be trimmed
     * @return trimmed String
     */
    public static String rtrim(String str) {
        int len = str.length();
        char[] val = str.toCharArray();
        int count = len;

        while (len > 0 && (val[len - 1] <= ' ')) {
            len--;
        }
        return (len < count) ? str.substring(0, len) : str;
    }
}

Related

  1. rtrim(String str)
  2. rtrim(String str)
  3. rtrim(String str)
  4. rtrim(String str)
  5. rTrim(String str)
  6. rTrim(String str)
  7. rtrim(String str, String charList)
  8. rtrim(String str, String defaultValue)
  9. rtrim(String str, String suffixs)