Java examples for java.lang:String Null Or Empty
Checks if a String is whitespace, empty ("") or null
public class Main{ public static void main(String[] argv){ String str = "java2s.com"; System.out.println(isBlank(str)); /*from ww w .j ava 2s . c om*/ str = ""; System.out.println(isBlank(str)); str = "null"; System.out.println(isBlank(str)); } /** * Checks if a String is whitespace, empty ("") or null. * * @param str * the String to check, may be null * @return true if the String is null, empty or whitespace */ public static boolean isBlank(String str) { return (str == null || str.trim().length() == 0); } }