How to check if list is empty in Java

1 Answer

0 votes
import java.util.List;
import java.util.Arrays;

public class MyClass {
    public static void main(String args[]) {
        List<String> list = Arrays.asList(); 

        if (list == null || list.isEmpty()) { 
            System.out.println("\nEmpty");
        } else {
            System.out.println("\nNot Empty");
        }
    }
}



/*
run:

Empty

*/

 



answered Apr 5, 2021 by avibootz

Related questions

2 answers 359 views
1 answer 330 views
1 answer 210 views
210 views asked Apr 5, 2021 by avibootz
1 answer 239 views
239 views asked Feb 16, 2021 by avibootz
3 answers 388 views
388 views asked Nov 1, 2020 by avibootz
1 answer 226 views
226 views asked Oct 10, 2020 by avibootz
...