Betafish Betafish - 1 year ago 95
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?

Answer Source

Look like the top object is null so

if (dbpedialookup != null && 
    dbpedialookup.variableBindings() != null &&
   !dbpedialookup.variableBindings().isEmpty()) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download