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 |
'프로그래밍 > Java' 카테고리의 다른 글
접근제어자 public, protected, private (0) | 2014.11.04 |
---|---|
① final 에 대한 이해 (0) | 2014.11.04 |
Vector, HashTable, Enumeration 예제 (0) | 2014.11.03 |
Model을 가지고 값 넣어주기 (0) | 2014.10.30 |
웹에서 세션(session)의 사용 (0) | 2014.10.29 |