check if list is not empty java code example
Example 1: how to check if a list is empty java
if (list != null && !list.isEmpty()) { do something }
Example 2: validation list empty java
public class ArrayListExample
{
public static void main(String[] args)
{
ArrayList<String> list = new ArrayList<>();
System.out.println(list.isEmpty()); //true
list.add("A");
System.out.println(list.isEmpty()); //false
list.clear();
System.out.println(list.isEmpty()); //true
}
}