Betafish Betafish - 2 months ago 25
Java Question

To check if List<Map<String, String>> is empty or not

The answer from a library (

) results in

List<Map<String, String>>

I am trying to check is if the list if empty or not.
What I have tried so far is

if (dbpedialookup.variableBindings() != null && !dbpedialookup.variableBindings().isEmpty()) {
System.out.println("Results Present);
} else {
System.out.println("No Results");

But, on items where the resultant List is []. Its throwing,

Exception in thread "main" java.lang.NullPointerException

How do we check for
in such a situation?


Look like the top object is null so

if (dbpedialookup != null && 
    dbpedialookup.variableBindings() != null &&
   !dbpedialookup.variableBindings().isEmpty()) {