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 225 views
1 answer 232 views
1 answer 147 views
147 views asked Apr 5, 2021 by avibootz
1 answer 152 views
152 views asked Feb 16, 2021 by avibootz
3 answers 250 views
250 views asked Nov 1, 2020 by avibootz
1 answer 136 views
136 views asked Oct 10, 2020 by avibootz
...