Evaluate if list is empty JSTL

JavaJspJstl

Java Problem Overview


I've been trying to evaluate if this array list is empty or not but none of these have even compiled:

<c:if test="${myObject.featuresList.size == 0 }">					
<c:if test="${myObject.featuresList.length == 0 }">					
<c:if test="${myObject.featuresList.size() == 0 }">					
<c:if test="${myObject.featuresList.length() == 0 }">					
<c:if test="${myObject.featuresList.empty}">					
<c:if test="${myObject.featuresList.empty()}">					
<c:if test="${myObject.featuresList.isEmpty}">	

How can I evaluate if an ArrayList is empty?

Java Solutions


Solution 1 - Java

empty is an operator:

> The empty operator is a prefix operation that can be used to determine > whether a value is null or empty.

<c:if test="${empty myObject.featuresList}">

Solution 2 - Java

There's also the function tags, a bit more flexible:

<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:if test="${fn:length(list) > 0}">

And here's the tag documentation.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOscarRyzView Question on Stackoverflow
Solution 1 - JavabobinceView Answer on Stackoverflow
Solution 2 - JavaSteve B.View Answer on Stackoverflow