Java String Trim Right rtrim(String value, int maxLength)

Here you can find the source of rtrim(String value, int maxLength)

Description

rtrim

License

Open Source License

Declaration

public static String rtrim(String value, int maxLength) 

Method Source Code

//package com.java2s;
/*//from w w  w . j  a  v  a 2s .c  o  m
 License:
    
 blueprint-sdk is licensed under the terms of Eclipse Public License(EPL) v1.0
 (http://www.eclipse.org/legal/epl-v10.html)
    
    
 Distribution:
    
 Repository - https://github.com/lempel/blueprint-sdk.git
 Blog - http://lempel.egloos.com
 */

public class Main {
    public static String rtrim(String value, int maxLength) {
        String result = nvl(value).trim();

        if (result.length() > maxLength) {
            result = result.substring(0, maxLength);
        }

        return result;
    }

    @SuppressWarnings("WeakerAccess")
    public static String nvl(Object value) {
        String result;
        if (value == null) {
            result = "";
        } else {
            result = value.toString().trim();
        }
        return result;
    }

    public static String nvl(Object value, String defaultValue) {
        String result = defaultValue;
        if (value != null) {
            result = value.toString();
        }
        return result;
    }
}

Related

  1. rtrim(String str, String defaultValue)
  2. rtrim(String str, String suffixs)
  3. rtrim(String string, String end)
  4. rtrim(String text, char c)
  5. rTrim(String value)
  6. rTrimObj(Object o)