is string an Empty string - Java java.lang

Java examples for java.lang:String Null Or Empty

Description

is string an Empty string

Demo Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Locale;
import java.util.regex.Pattern;

public class Main{

    public static void main(String[] argv){
        String str = "java2s.com";
        System.out.println(isEmpty(str));
        /*from  w ww .  j a  va 2 s.co m*/
        str = "";
        System.out.println(isEmpty(str));
        
        str = null;
        System.out.println(isEmpty(str));
    }

    public static boolean isEmpty(String str) {
        return str == null || str.trim().length() == 0
                || str.trim().equalsIgnoreCase("null");
    }

}

Related Tutorials