isEmpty Null 체크하기
String str1 = "JavaCodeGeeks isEmpty Example";
String str2 = "";
String str3 = " "; //this String is not considered as empty
boolean check1 = str1.isEmpty();
boolean check2 = str2.isEmpty();
System.out.println("Is str1 empty? The answer is: "+str1.isEmpty() );
System.out.println("Is str1 empty? The answer is: "+check1 );
System.out.println("Is str2 empty? The answer is: "+str2.isEmpty() );
System.out.println("Is str2 empty? The answer is: "+check2 );
System.out.println("Is str3 empty? The answer is: "+str3.isEmpty() );
System.out.println("Is str3 empty? The answer is: "+str3.trim().isEmpty() );
결과 :
Is str1 empty? The answer is: false |