There's a key difference between a null array and an empty array. This is a test for null.

int arr[] = null;
if (arr == null) {
  System.out.println("array is null");
}

"Empty" here has no official meaning. I'm choosing to define empty as having 0 elements:

arr = new int[0];
if (arr.length == 0) {
  System.out.println("array is empty");
}

An alternative definition of "empty" is if all the elements are null:

Object arr[] = new Object[10];
boolean empty = true;
for (int i=0; i<arr.length; i++) {
  if (arr[i] != null) {
    empty = false;
    break;
  }
}

or

Object arr[] = new Object[10];
boolean empty = true;
for (Object ob : arr) {
  if (ob != null) {
    empty = false;
    break;
  }
}
Answer from cletus on Stack Overflow
🌐
Quora
quora.com › What-is-a-null-array-in-Java
What is a null array in Java? - Quora
Answer: This simply means that no array actually exists. You can have an array with elements that are all set to null this is the default for an array of references when it's initially created , You can have a null array reference sample can ...
🌐
Coderanch
coderanch.com › t › 629154 › java › length-null-array-object
what is the length of a null array object? (Beginning Java forum at Coderanch)
Jeremy McNally wrote:When you have a 'null' array, your array has absolutely nothing in it. Jeremy McNally wrote:You create an empty array, you are doing the exact same thing. The program tries to find the array and finds it BUT there is nothing in ... No. There is no array at all.
🌐
Overclock.net
overclock.net › home › forums › software, programming and coding › coding and programming
How can I set an element in an array to null? (java) | Overclock.net
This is what I did: for(j = 0; j < 10; j++) // j is which element in list { compare = delpass.compareTo(pw[j]); if(compare == 0) pw[j].equals(null); //pw and nm are arrays nm[j].equals(null); } delpass is the password the user wants to delete, so basically I am finding the element that matches this password and trying to set it equal to null again but I cant because null is a java key term.
🌐
Delft Stack
delftstack.com › home › howto › java › how to check whether an array is null empty
How to Check Whether an Array Is Null/Empty in Java | Delft Stack
February 2, 2024 - In Java, an array is an object that holds similar types of data. It can be null only if it is not instantiated or points to a null reference.
Find elsewhere
🌐
Rip Tutorial
riptutorial.com › pitfall - using null to represent an empty array or collection
Java Language Tutorial => Pitfall - Using null to represent an...
/** * Sum the values in an array of integers. * @arg values the array to be summed, or null. * @return the sum, or zero if the array is null.
🌐
TutorialsPoint
tutorialspoint.com › when-does-a-java-array-throws-a-nullpointerexception
When does a Java Array Throws a NullPointerException?
If you try to access the elements of an array which is not initialized yet (which is null). public class Demo { public static void main(String args[]) { int myArray[] = null; System.out.println(myArray[5]); } } Exception in thread "main" java.lang.NullPointerException at july_set3.Demo.main(Demo.java:6)
🌐
DaniWeb
daniweb.com › programming › software-development › threads › 430398 › check-whether-an-element-array-is-null
java - check whether an element array is null | DaniWeb
A quick practical follow-up that builds on @stultuske and @rajesh1158: primitives (like int) cannot be null, so you get compile errors when you try array[i] == null or array[i].equals(...).
🌐
Quora
quora.com › How-can-I-set-a-character-array-to-null-in-Java-Or-empty-it
How to set a character array to null in Java? Or empty it - Quora
Answer (1 of 6): [code]class EmptyCharArray{ public static void main(string[] args) { char namearray[6] = {'a', 'n', 'm', 'o', 'l'}; for(int i=0;i
🌐
Baeldung
baeldung.com › home › java › java array › difference between null and empty array in java
Difference Between null and Empty Array in Java | Baeldung
August 10, 2024 - In this article, we have examined the distinctions between null and empty arrays in Java. A null array signifies that the array reference doesn’t point to any object, leading to potential NullPointerException errors if accessed without proper null checks.
🌐
Reddit
reddit.com › r/learnprogramming › [java] null pointer exception with respect to an array of objects
r/learnprogramming on Reddit: [Java] Null Pointer Exception with respect to an array of objects
October 25, 2014 -

Hey r/learnprogramming, I'm doing this project for school and I can't seem to figure out why I'm receiving this null pointer exception. I believe the object is null on initialization, but I'm trying to use a setter method from inside the class to scan in a line of text one at a time from a file.

Luckily it's not due for about a week (thankful that I started this early) so I'm not in too much of a panic, but I'd like to at least get past this error so I can start writing some of my methods.

The error I receive is

Exception in thread "main" java.lang.NullPointerException
at Micsa.main(n00737298.java:21)

Here is my code

I'd appreciate any help or even just a pointer (lol) in the right direction. I feel like it's right in front of me but maybe I've just been staring at my monitor too long.

Thank you!

🌐
GeeksforGeeks
geeksforgeeks.org › java › java-array-empty-check
Java Array Empty Check - GeeksforGeeks
July 23, 2025 - In Java, an array is considered non-empty, if it is not null and its length is greater than 0.
🌐
Java2Blog
java2blog.com › home › core java › java array › check if array is empty in java
Check if Array Is Empty in Java - Java2Blog
March 4, 2022 - When the array is not instantiated, the array variable has a null reference making it an empty array. For example, ... > You should note that Java doesn’t allow you to use an uninitialized local variable.
🌐
Quora
quora.com › Can-an-array-store-null-values
Can an array store null values? - Quora
Answer (1 of 8): Most languages that have a concept of null will allow you to store null values in arrays, as you didn’t reference a particular language I will point out that C++ is a typed language, and if you have an array of pointers you can store nullptr in there, and we often use that as a c...
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-check-if-an-array-is-empty-or-not-in-java
How to Check if an Array is Empty or Not in Java? - GeeksforGeeks
July 23, 2025 - Explanation: The array == null checks if the array reference is uninitialized or null and the array.length == 0 checks if the array has no elements. If we need to check arrays frequently, we can create a reusable utility method to simplify array ...