You can by using the varStatus
attribute and EL brace notation:
<c:forEach items="${customerlist}" var="customer" varStatus="i">
<c:choose>
<c:when test="${not i.first and customerlist[i.index] eq customerlist[i.index - 1]}">
[do some stuff]
</c:when>
<c:otherwise>
[do other stuff]
</c:otherwise>
</c:choose>
</c:forEach>
So, check if you are not doing the fist iteration (since there is no previous object), using the varStatus
first
property:
not i.first
And then compare based on the varStatus
index
property
customerlist[i.index] eq customerlist[i.index - 1]
Alternatively you could use begin="1"
in c:forEach
to skip the first item in the list if you are sure there are more items in the list.