No, absolutely not - because if acct is null, it won't even get to isEmpty... it will immediately throw a NullPointerException.

Your test should be:

if (acct != null && !acct.isEmpty())

Note the use of && here, rather than your || in the previous code; also note how in your previous code, your conditions were wrong anyway - even with && you would only have entered the if body if acct was an empty string.

Alternatively, using Guava:

if (!Strings.isNullOrEmpty(acct))
Answer from Jon Skeet on Stack Overflow
🌐
Medium
medium.com › @ecetasci.iu › checking-for-null-or-empty-strings-in-java-19518fa1e553
Checking for Null or Empty Strings in Java | by Ece Tasci | Medium
February 25, 2025 - An empty String ("") has zero characters but still exists in memory, specifically in the heap where Java stores objects. A null String, however, does not point to any memory location; it is simply a reference that has not been assigned an object.
Discussions

Why does the order of String == null || String.isEmpty() matter? Or does it?
|| is fail fast. So if the first or condition gets evaluated to true it doesn't even check the second one. If there is a null string you can't check it's contents and will receive a Nullpointer exception. checking whether it is null first removed that risk. More on reddit.com
🌐 r/learnjava
22
10
May 3, 2019
What is the correct way to check if a String is empty or null in Java, and how can I avoid potential errors? - TestMu AI Community
I’m parsing HTML data, and sometimes the string might be either null or an empty string. Here’s the condition I wrote to handle it: if(string.equals(null) || string.equals("")){ Log.d("iftrue", "seem to be true"); }else{ Log.d("iffalse", "seem to be false"); } However, this doesn’t always ... More on community.testmu.ai
🌐 community.testmu.ai
0
March 2, 2025
If a string is null, doesn't isEmpty() throw a Nullpointerexception when used?
Elias Caceres is having issues with: Shouldnt we check for isEmpty OR ==null? At least thats how I remember it... But i might be worng. More on teamtreehouse.com
🌐 teamtreehouse.com
1
July 16, 2015
Shorter (efficient) way to check if a string is null or empty?
[The Java String class has an isEmpty method]( https://docs.oracle.com/javase/7/docs/api/java/lang/String.html#isEmpty() More on reddit.com
🌐 r/learnjava
12
2
March 1, 2020
🌐
W3Schools
w3schools.com › java › ref_string_isempty.asp
Java String isEmpty() Method
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. ... If you want to use W3Schools services as an educational institution, team or enterprise, send ...
🌐
Reddit
reddit.com › r/learnjava › why does the order of string == null || string.isempty() matter? or does it?
r/learnjava on Reddit: Why does the order of String == null || String.isEmpty() matter? Or does it?
May 3, 2019 -

I just completed MOOC, Java part II, exercise 19 for week 9 and found that the order I placed name.isEmpty() or name == null was the key to get it's tests to pass.

The test which failed was one that tested a null but I don't understand why it matters since it's an or statement.

Thank You

So this fails

    public Person(String name, int age) {
        if ( name.isEmpty() || name == null ||  name.length() > 40) {
            throw new IllegalArgumentException("Name is an invalid length.");
        } else {
            this.name = name;
        }

        if ((age < 0) || (age > 120)) {
            throw new IllegalArgumentException("Age is not a valid range");
        } else {
            this.age = age;
        }
    }

But this passes

    public Person(String name, int age) {
        if (  name == null || name.isEmpty() || name.length() > 40) {
            throw new IllegalArgumentException("Name is an invalid length.");
        } else {
            this.name = name;
        }

        if ((age < 0) || (age > 120)) {
            throw new IllegalArgumentException("Age is not a valid range");
        } else {
            this.age = age;
        }
    }
🌐
Baeldung
baeldung.com › home › java › java array › checking if an array is null or empty in java
Checking if an Array Is Null or Empty in Java | Baeldung
July 16, 2024 - Apache Commons Lang 3 is a widely used library. Its ArrayUtils class provides a rich set of utilities, making array manipulation easier. The class offers an isEmpty() method to check whether an array is null or empty.
🌐
Sumo Logic
sumologic.com › log search › search query language › search operators › isnull, isempty, isblank
isNull, isEmpty, isBlank Search Operators | Sumo Logic Docs
November 6, 2025 - The isNull operator checks a string and returns a boolean value: true if the string is null, or false if the string is not null. The isEmpty operator checks if a string contains no characters and is only whitespace.
🌐
Scaler
scaler.com › home › topics › isempty() in java
Java String isEmpty - Scaler Topics
January 4, 2024 - The String is empty is returned for the first case because str==null is true, and in the second case the condition str1.isEmpty() is true that's why the String is empty is returned.
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java string › checking for empty or blank strings in java
Checking for Empty or Blank Strings in Java | Baeldung
January 8, 2024 - We consider a string to be empty if it’s either null or a string without any length. If a string only consists of whitespace, then we call it blank. For Java, whitespaces are characters, like spaces, tabs, and so on. We can check out Character.isWhitespace for examples. If we’re at least on Java 6, then the simplest way to check for an empty string is String#isEmpty:
🌐
TestMu AI Community
community.testmu.ai › ask a question
What is the correct way to check if a String is empty or null in Java, and how can I avoid potential errors? - TestMu AI Community
March 2, 2025 - I’m parsing HTML data, and sometimes the string might be either null or an empty string. Here’s the condition I wrote to handle it: if(string.equals(null) || string.equals("")){ Log.d("iftrue", "seem to be true"); }…
🌐
Google Groups
groups.google.com › g › guava-discuss › c › Ar7HSlvlS4A
null-safe isEmpty for Iterables
To further support the argument of NEVER using null as meaning "empty": It is virtually cost-less to return an immutable empty collection using the java.util.Collections.emptyXxx() methods, which returns empty immutable singletons and even does a good job of type inference.
🌐
Medium
medium.com › @lp.lok.payu › isempty-vs-empty-vs-isblank-vs-isnull-12aea580fe4b
isEmpty() vs empty() vs isBlank() vs isNull() | by leela prasad | Medium
February 16, 2025 - The isEmpty operator checks if a string contains no characters and is only whitespace. The isBlank operator checks if a string contains no characters, is only whitespace, and is null. “Enjoyed this article?
🌐
Reddit
reddit.com › r/learnjava › shorter (efficient) way to check if a string is null or empty?
Shorter (efficient) way to check if a string is null or empty? : r/learnjava
March 1, 2020 - Use the guava library, StringUtils.isEmpty(“string”) hfontanez · • 6y ago · You probably meant StringUtils.nullOrEmtpy(s) Ramlaen · • 6y ago · Yea was not in front of an ide More replies More replies · hfontanez · • 6y ago · If you are using core Java, that's the best way.
🌐
Medium
medium.com › @AlexanderObregon › java-string-isempty-method-explained-a731faf082aa
Java String isEmpty() Method Guide | Medium
June 23, 2024 - In scenarios where a string could be null, it is essential to check for null before calling isEmpty().
🌐
Stack Abuse
stackabuse.com › java-check-if-string-is-null-empty-or-blank
Java: Check if String is Null, Empty or Blank
February 28, 2023 - Note: It's important to do the null-check first, since the short-circuit OR operator || will break immediately on the first true condition. If the string, in fact, is null, all other conditions before it will throw a NullPointerException. The isEmpty() method returns true or false depending ...
🌐
Tutorialspoint
tutorialspoint.com › home › java/lang › java string isempty method
Java String isEmpty Method
September 1, 2008 - Because Null is a placeholder that generally means, "no data is available about this", and it is not the same as an empty string, the compiler cannot handle it and throws a NullPointerException.
🌐
TestMu AI Community
community.testmuai.com › ask a question
Best Way to Check if a String is Null or Empty in Java - TestMu AI Community
March 19, 2025 - What is the best way to check if a String is null or empty in Java? I’m currently parsing HTML data, and sometimes the String can be null or empty when the expected word doesn’t match. To handle this, I wrote the following check: if(string.equals(null) || string.equals("")){ Log.d("iftrue", "seem to be true"); }else{ Log.d("iffalse", "seem to be false"); } However, when I remove string.equals(""), the condition doesn’t work correctly.
🌐
Vultr Docs
docs.vultr.com › java › examples › check-if-a-string-is-empty-or-null
Java Program to Check if a String is Empty or Null | Vultr Docs
December 17, 2024 - Explore practical examples that showcase these techniques to help you integrate them into your Java applications seamlessly. Use the basic logical operations directly to check if a string is null or empty. ... public static boolean isNullOrEmpty(String str) { if (str == null || str.isEmpty()) { return true; } return false; } Explain Code