Java String Sub String subStr(String str, int len)

Here you can find the source of subStr(String str, int len)

Description

sub Str

License

Open Source License

Declaration

public static String subStr(String str, int len) 

Method Source Code

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

public class Main {
    public static String subStr(String str, int len) {
        if (isEmpty(str)) {
            return "";
        }/*from ww w .j a  va  2  s  .c  o  m*/
        if (str.length() >= len) {
            return str.substring(0, len) + "..";
        } else {
            return str;
        }
    }

    public static boolean isEmpty(String src) {
        if (src == null || src.trim().equals("null") || src.trim().equals(""))
            return true;
        return false;
    }

    public static boolean equals(String str1, String str2) {
        if (str1 == null) {
            return str2 == null;
        }

        return str1.equals(str2);
    }
}

Related

  1. substr(String src, int nStart, int nLen)
  2. subStr(String src, String split)
  3. substr(String str, int beginIndex, int endIndex)
  4. substr(String str, int iLen)
  5. substr(String str, int index)
  6. substr(String str, int length)
  7. subStr(String str, int limit)
  8. subStr(String str, int maxLen)
  9. substr(String str, int startIndex, int length)