How to check whether an int array is null or empty in Java

2 Answers

0 votes
public class MyClass {
    public static void main(String[] args) {
        int[] array = null;

        if (array == null) {
            System.out.println("Array is null");
        }
    }
}
   
   
   
   
   
/*
run:
       
Array is null

*/

 



answered Nov 16, 2023 by avibootz
0 votes
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;

public class MyClass {
    public static void main(String[] args) {
        int[] array = new int[0];

        if (array.length == 0) {
            System.out.println("Array is empty");
        }
    }
}
   
   
   
   
   
/*
run:
       
Array is empty

*/

 



answered Nov 16, 2023 by avibootz

Related questions

...