Check string length and if it is empty

ReturnMethodSummary
booleanisEmpty()Returns true if, and only if, length() is 0.
intlength()Returns the length of this string.

public class Main {
  public static void main(String[] argv) {
    String str = "";
    System.out.println(str.isEmpty());
    System.out.println(str.length());
    
    str = "java2s.com";
    System.out.println(str.isEmpty());
    System.out.println(str.length());
  }
}

The output:


true
0
false
10
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.