String str1 = ""; // an empty string if(str1.isEmpty()){ System.out.println("The string is empty"); } else { System.out.println("The string is not empty"); } // Output: The string is empty
String str2 = "Hello World"; // a non-empty string if(str2.isEmpty()){ System.out.println("The string is empty"); } else { System.out.println("The string is not empty"); } // Output: The string is not emptyThis method is defined in the java.lang.String class, which is part of the Java Standard Library. Therefore, it belongs to the java.lang package.