Ungefähr 7.540 Ergebnisse
Links auf neuer Registerkarte öffnen
  1. The isEmpty() method in Java is used to check whether a string is empty or not. It returns true if the string has a length of 0, and false otherwise.

    Example

    public class IsEmptyExample {
    public static void main(String[] args) {
    String str1 = "";
    String str2 = "Hello";

    System.out.println(str1.isEmpty()); // true
    System.out.println(str2.isEmpty()); // false
    }
    }
    Kopiert!

    Important Considerations

    • Null Strings: The isEmpty() method does not check for null strings. If you try to call isEmpty() on a null string, it will throw a NullPointerException. To handle this, you can use an additional null check.

    public class NullCheckExample {
    public static void main(String[] args) {
    String str = null;

    if (str == null || str.isEmpty()) {
    System.out.println("String is null or empty");
    } else {
    System.out.println("String is not empty");
    }
    }
    }
    Kopiert!
  2. Java String isEmpty () Method - W3Schools

    Definition and Usage The isEmpty() method checks whether a string is empty or not. This method returns true if the string is empty (length () is 0), and false if not.

  3. Java String isEmpty() Method with Example - GeeksforGeeks

    20. Nov. 2024 · In Java, the String isEmpty () method checks if a string is empty (length is zero). This method returns true if the string is empty and false otherwise. It is useful for validating strings in our …

  4. Difference Between String isEmpty() and isBlank()

    23. Nov. 2023 · In this article, we’ll look at how to validate blank and empty Strings using the isEmpty () and isBlank () methods. Although similar, the two methods …

  5. Mastering `isEmpty()` in Java - javaspring.net

    12. Nov. 2025 · Understanding how to use `isEmpty ()` effectively can make your code more readable, maintainable, and efficient. In this blog post, we'll delve into the fundamental concepts, usage …

  6. Java String isEmpty () method - Tpoint Tech

    17. März 2025 · The isEmpty () method in Java is a part of the String class and is used to check whether a string is empty or not. It returns a boolean value true if the string is empty (contains no characters), …

    Codebeispiel

    String s1="";
    String s2="javatpoint";
    System.out.println(s1.isEmpty());
    System.out.println(s2.isEmpty());
    }}...
  7. Java String isEmpty () method - BeginnersBook

    9. Juni 2024 · The String.isEmpty() method is a simple method to check if a string is empty in Java. It is generally used along with trim() method and null checks to validate string content.

  8. Ähnliche Fragen
  9. Java String isEmpty () Method

    The String.isEmpty() method in Java is used to check if a string is empty (i.e., has a length of zero). This guide will cover the method's usage, explain how it works, and provide examples to demonstrate its …

  10. Java String.isEmpty () - Baeldung

    11. Apr. 2025 · A quick example and explanation of the isEmpty API of the standard String class in Java.

  11. Java String isEmpty () - Programiz

    The Java String isEmpty () method checks whether the string is empty or not. In this tutorial, you will learn about the Java String isEmpty () method with the help of an example.

  12. How to Check if a String Is Empty or Null in Java - Delft …

    11. März 2025 · This article explores how to check if a string is empty or null in Java, providing practical methods and examples. Learn about the differences …