Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

varStatus in c:forEach

 
Rahul Jadaun
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of 'varStatus' in <c:forEach>

getCount() starts from 1 while getIndex() starts from 0.
Please confirm.
 
Ashwini Hegde
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, that is correct. getIndex() is 0-based and getCount() is 1-based.

Following is an extract from the JSTL 1.1 specifications document
------------------------------------------------------------------
  • public int getIndex()Retrieves the index of the current round of the iteration. If the iteration is being performed over a subset of an underlying array, java.lang.Collection, or other type, the index returned is absolute with respect to the underlying collection.

  • Indices are 0-based.
    Returns
    The 0-based index of the current round of the iteration
  • public int getCount()

  • Retrieves the count of the current round of the iteration. The count is a relative, 1-based sequence number identifying the current round of iteration (in context with all rounds the current iteration will perform). As an example, an iteration with begin = 5, end = 15, and step = 5 produces the counts 1, 2, and 3 in that order.

    [b]Returns/[b]
    The 1-based count of the current round of the iteration

    ------------------------------------------------------------------------
     
    Rahul Jadaun
    Ranch Hand
    Posts: 36
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Ashwini..!
     
    Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
    the new thread boost feature: great for the advertiser and smooth for the coderanch user
    https://coderanch.com/t/674455/Thread-Boost-feature
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!