Java String Trim Right rtrim(String s)

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

Description

Trims specified string from right.

License

Open Source License

Parameter

Parameter Description
s a parameter

Declaration

public static String rtrim(String s) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w  w w . ja  v  a 2 s. co  m
     * Trims specified string from right.
     * @param s
     */
    public static String rtrim(String s) {
        if (s == null) {
            return null;
        }

        int len = s.length();
        int index = len;

        while (index > 0 && Character.isWhitespace(s.charAt(index - 1))) {
            index--;
        }

        return (index <= 0) ? "" : s.substring(0, index);
    }
}

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)