Search code examples
javaspringjspjstl

How to do a certain task only with the first output of a foreach loop?


I want to output values of a list like this, but also I want to prepend another value to only the first element of the list, i.e. valuesInRow[0]. How do I do this while also outputting the other values in the list without the prepend?

<c:forEach var="valuesInRow" items="${valuesInRows}">                                        
  <td>${idPrepend}${valuesInRow}</td>
</c:forEach>

Solution

  • You can use varStatus: How to get a index value from foreach loop in jstl

    It will give you some control about the loop.