If you use the Apache Commons Collections library in your project, you may use the CollectionUtils.isEmpty(...) and MapUtils.isEmpty(...) methods which respectively check if a collection or a map is empty or null (i.e. they are "null-safe").

The code behind these methods is more or less what user @icza has written in his answer.

Regardless of what you do, remember that the less code you write, the less code you need to test as the complexity of your code decreases.

Answer from Jalayn on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › list-isempty-method-in-java-with-examples
List isEmpty() method in Java with Examples - GeeksforGeeks
December 3, 2024 - // Java Progrm to Implement // List isEmpty() Method import java.util.*; class Main { public static void main (String[] args) { // New empty list created List<Integer> l=new ArrayList<>(); // Implementing isEmpty() Method if(l.isEmpty()) System.out.println("List is Empty"); else System.out.println("List is not Empty"); } } ... Parameter : It does not accept any parameter. Return Type : It returns True if the list has no elements else it returns false. The return type is of datatype boolean. Error and Exceptions : This method has no errors or exceptions. ... // Java Program Implementing // List
🌐
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 - Checking if an array is null or empty is a fundamental task in Java programming. In this article, we’ve explored how to implement these checks for both object and primitive type arrays, creating a robust utility method that can be reused in our applications.
🌐
Javacodehouse
javacodehouse.com › blog › java-nullable-list-first-item
Java 8 Optional - Avoid the explicit null check on list
How to get the first item of a nullable list in Java using Optional · public static void main(String[] args) { // List<String> items = null; List<String> items = List.of("1", "2", "3"); if (items != null && !items.isEmpty()) { String firstItem = items.get(0); System.out.println("First item: " + firstItem); } else { System.out.println("List is null or empty"); } } This is simple and widely understood by Java developers.
🌐
Medium
medium.com › @malvin.lok › how-java-elegantly-determines-null-or-empty-d809fc136c7d
How Java Elegantly Determines Null or Empty? | by Malvin Lok | Medium
August 8, 2023 - So it’s common to concatenate list ! = null && list.size > 0 to determine whether is empty. But we could use: ... Backend Engineer, focus on Java. Haft-way full-stack developer, interested in React/Flutter.
🌐
TutorialsPoint
tutorialspoint.com › home › commons_collections › safe checks in apache commons collections
Apache Commons Collections - Safe Empty Checks
August 14, 2018 - True if empty or null. The following example shows the usage of org.apache.commons.collections4.CollectionUtils.isEmpty() method. We'll check a list is empty or not. package com.tutorialspoint; import java.util.List; import org.apache.commons.collections4.CollectionUtils; public class CommonCollectionsTester { public static void main(String[] args) { List<String> list = getList(); System.out.println("Empty List Check: " + checkEmpty1(list)); System.out.println("Empty List Check: " + checkEmpty1(list)); } static List<String> getList() { return null; } static boolean checkEmpty1(List<String> list) { return (list == null || list.isEmpty()); } static boolean checkEmpty2(List<String> list) { return CollectionUtils.isEmpty(list); } } Given below is the output of the code − ·
🌐
Baeldung
baeldung.com › home › java › java string › how to find null or empty strings in a java list
How to Find Null or Empty Strings in a Java List | Baeldung
October 8, 2025 - Note that isEmpty() treats ” “ as non-empty; we can handle that case using the isBlank() method. Now, let’s implement the same check with Streamin one line: @Test void givenListWithNullOrEmpty_whenCheckForNullOrEmptyUsingStreams_thenReturnTrue() { boolean hasNullOrEmpty = list.stream() .anyMatch(s -> s == null || s.isEmpty()); assertTrue(hasNullOrEmpty, "List should contain null or blank elements"); }
🌐
Scalabledeveloper
scalabledeveloper.com › posts › list-is-empty-in-java
A couple of ideas to check that list is empty in Java | Scalable Developer
Suppose, at some point of code we receive variable list of type List<Integer> and we need to sum all numbers only if list is not empty. What is the most elegant way to check that list is not empty? ... List is not null, but it does not guarantee that list is not empty.
Find elsewhere
🌐
Reddit
reddit.com › r/programming › should i return a null value or an empty collection?
r/programming on Reddit: Should I return a null value or an empty collection?
July 4, 2012 - If you're returning a list by value it doesn't make sense to check for null because lists are concrete things that can't be compared against null. If you really want to return a "pointer to list" or "Maybe list" you should be able to, but forcing you to return a pointer is a shitty language decision. ... The issue here in reality is orthogonal to value vs. reference. Basically, in a language like Java, you'd like to distinguish the type of a reference that definitely points to some object from the type of a reference that either points to an object or to nothing.
🌐
W3Docs
w3docs.com › java
Does java.util.List.isEmpty() check if the list itself is null?
No, the isEmpty() method of the java.util.List interface does not check if the list itself is null. It only checks if the list is empty, i.e.
🌐
LabEx
labex.io › tutorials › java-how-to-check-if-a-list-is-empty-in-java-559949
How to Check If a List Is Empty in Java | LabEx
Save the ListCheck.java file. ... Is emptyList empty? true Is populatedList empty? false Size of emptyList: 0 Size of populatedList: 2 Safely checking for null: nullList is null. Is emptyList empty? true Size of emptyList: 0 · Notice that we ...
🌐
Java Guides
javaguides.net › 2019 › 04 › check-if-collection-is-empty-or-null-in-java.html
Check if a Collection is Empty or Null in Java
June 21, 2024 - This guide will cover various ... a real-world use case to illustrate its application. ... In Java, a collection can be either null or contain no elements....
🌐
How to do in Java
howtodoinjava.com › home › collections framework › java arraylist › check if an arraylist is empty in java
Check if an ArrayList is Empty in Java
January 12, 2023 - In application programming, it is advisable to check both if list is not null and then not empty. If list is not initialized, we may get NullPointerException in runtime. Another way to check if the arraylist contains any element or not, we can check the size of the arraylist.
🌐
Vultr
docs.vultr.com › java › standard-library › java › util › ArrayList › isEmpty
Java ArrayList isEmpty() - Check If Empty | Vultr Docs
November 5, 2024 - The isEmpty() method in Java's ArrayList class is a straightforward tool to check if the list contains no elements. It returns true if the list is empty; otherwise, it returns false.
🌐
Javapractices
javapractices.com › topic › TopicAction.do
Java Practices->Prefer empty items to null ones
If stocks has no elements at all, then toArray will simply return the NO_STOCKS array itself. */ return stocks.toArray(NO_STOCKS); } // PRIVATE /** The underlying collection. */ private List<String> stocks; /** A constant, empty array, to be used instead of a null array.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Find Null or Empty Strings in a Java List Example - Java Code Geeks
September 16, 2025 - Line 11-13: adds to a mutable list if the element is null or isEmpty inside the For loop. Note: if the blank space (” “) is considered as empty, then change the isEmpty to isBlank. Line 23-25: verify the returned list contains null or empty. Run ForLoopAddImpl.java and capture output.
🌐
Baeldung
baeldung.com › home › java › java array › null array to empty list in java
Null Array to Empty List in Java | Baeldung
April 7, 2025 - Importantly, if the original array is null or empty, our final list will be empty. Now, let’s look at a few approaches. In our first implementation, we’ll use the Java Streams API.
🌐
Google Groups
groups.google.com › g › guava-discuss › c › mfD6uP9QopM
Elegant null-empty collection checks
It checks whether given collection is null. If so, it returns new empty collection (or the original one otherwise). public static <T> Collection<T> nullToEmpty(Collection<T> collection) { if (collection == null) { return Lists.newLinkedList(); } return collection; } I find it useful when dealing ...