Java String Left left(String str, int len)

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

Description

Get substring from left

License

LGPL

Parameter

Parameter Description
str string
len length

Return

substring from left

Declaration

public static String left(String str, int len) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

public class Main {
    /**/*from  www.ja  v  a  2 s .c  o m*/
     * Get substring from left
     * @param str string
     * @param len length
     * @return substring from left
     */
    public static String left(String str, int len) {
        if (!nullOrEmpty(str) && str.length() > len) {
            return str.substring(0, len);
        }
        return str;
    }

    public static boolean nullOrEmpty(String s) {
        return (s == null) ? true : "".equals(s.trim());
    }

    public static String trim(String s) {
        return emptyIfNull(s).trim();
    }

    public static String emptyIfNull(String s) {
        return (s == null) ? "" : s;
    }
}

Related

  1. left(String source, String searchFor)
  2. left(String str, int count)
  3. left(String str, int len)
  4. left(String str, int len)
  5. left(String str, int len)
  6. left(String str, int len, String appendStrIfOver)
  7. left(String str, int length)
  8. left(String str, int size)
  9. left(String string, int length)