JSTL Last Using varStatus

JSTL Last Using varStatus Example explains about finding JSTL last count using varStatus
Consider a JSP page, which contains an ArrayList and we need to find the last count of that particular ArrayList
For this by declaring variable varStatus="status" in JSTL forEach, you can access all the available methods of status object inside JSP page
You can use 'status.last' inside c:forEach tag, this will find the last element of that particular ArrayList
This JSTL 'status.last' is available for all the List / Collection implementations in java
you can see the below example demonstrating JSTL 'status.last'
Required Libraries
JSTL Last Using varStatus
// JSTL varStatus Example <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <%@ page import="java.util.ArrayList"%> <% ArrayList<String> numList = new ArrayList<String>(); numList.add("1"); numList.add("2"); numList.add("3"); request.setAttribute("numList", numList); %> <html> <body> <c:forEach items="${numList}" var="item" varStatus="status"> <c:if test="${status.last}">${item}</c:if> </c:forEach> </body> </html>
Output
3The status object have following useful methods: