Java String Trim Right rtrim(String s)

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

Description

Right trims a string.

License

Open Source License

Parameter

Parameter Description
s the string to rtrim.

Return

a trimmed string.

Declaration

public static String rtrim(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w  ww .j  a  va  2s. c o m
     * Right trims a string.
     * @param s the string to rtrim.
     * @return a trimmed string.
     */
    public static String rtrim(String s) {
        if (s == null)
            return null;

        for (int k = s.length() - 1; k >= 0; k--) {
            if (!Character.isWhitespace(s.charAt(k)))
                return (k == s.length() - 1 ? s : s.substring(0, k + 1));
        }
        return "";
    }
}

Related

  1. rtrim(String s)
  2. rtrim(String s)
  3. rTrim(String s)
  4. rtrim(String s)
  5. rtrim(String s)
  6. rtrim(String s)
  7. rtrim(String s)
  8. rtrim(String s)
  9. rtrim(String s)