Search code examples
listforeachjstlskip

How to skip first element of List in c:forEach


I'm using <c:forEach> to iterate over a List like below:

<c:forEach items="${list}" var="item">
    ${item}
</c:forEach>

How can I skip printing of the first item of the list?


Solution

  • You can use varStatus attribute to get hold of the iteration status which in turn has among others a isFirst() method which you could check in a <c:if> block.

    <c:forEach items="${list}" var="item" varStatus="loop">
        <c:if test="${not loop.first}">
            ${item}
        </c:if>
    </c:forEach>