Java String Sub String subStringRight(String str, int length)

Here you can find the source of subStringRight(String str, int length)

Description

sub String Right

License

Open Source License

Declaration

public static String subStringRight(String str, int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static String subStringRight(String str, int length) {
        if (str == null || str.isEmpty())
            return str;
        return str.substring(str.length() - min(str.length(), length));
    }/*from w  w w. j  av a  2  s. c o m*/

    /**
     * Check if Object (String) is empty or null (leading and trailing whitespaces and<br>
     * other chars like linefeed chars, etc. are omitted/ignored, like it was done in<br>
     * String.trim() method )
     *
     * @param object
     * @return boolean, true if empty or null
     * @see empty
     */
    public static boolean isEmpty(final CharSequence s) {
        int len;
        if (null != s && (len = s.length()) != 0)
            while (len > 0)
                if (s.charAt(--len) > ' ')
                    return false;
        return true;
    }

    public static String substring(String in, int maxlength) {

        if (in.length() > maxlength) {
            return in.substring(0, maxlength);
        }
        return in;
    }

    private static int min(int a1, int a2) {
        return a1 < a2 ? a1 : a2;
    }
}

Related

  1. substringMatch(CharSequence str, int index, CharSequence substring)
  2. substringMatches(final String source, final String substring, final boolean checkBoundaries)
  3. substringMore(String s, int maxlen)
  4. subStringNobit(String str, int toCount, String more)
  5. subStringNotEncode(String subject, int size)
  6. substrings(String str, int start, int end)
  7. subStrings(String str1, String str2)
  8. substrings(String[] arr, int start, int end)
  9. subStringToInteger(String src, String start, String to)