Checks if a String is empty ("") or null without using trim method - Java java.lang

Java examples for java.lang:String Null Or Empty

Description

Checks if a String is empty ("") or null without using trim method

Demo Code

import java.util.Random;

public class Main{

    public static void main(String[] argv){
        String str = "java2s.com";
        System.out.println(isBlankNoTrim(str));
    }/*from   www.j a va 2s  .co m*/
    /**
     * Checks if a String is empty ("") or null.
     * 
     * @param str
     *            the String to check, may be null
     * @return true if the String is null or empty
     */
    public static boolean isBlankNoTrim(String str) {
        return (str == null || str.length() == 0);
    }

}

Related Tutorials