How to iterate a LinkedHashMap using index variable in JSTL

1.3k Views Asked by At

Can you please suggest how to iterate a LinkedHashMap using index variable. It important to that I use index variable to iterate the map. I need the index to access the value somewhere else in the same map

Map<String,List<String>> map = new LinkedHashMap<String,List<String>>();    

I have written the java code. And trying hard to convert this code in JSTL.

int listcount = 8;

for (Map.Entry<String, List<String>> entry : map.entrySet())
{               

          List<String> lst = new ArrayList<String>();
          lst= entry.getValue();
          System.out.println(":::::::"+entry.getKey()+":::::::");

          for(int i=0;i<listcount;i++){                     
                        System.out.println(lst.get(i));
                        System.out.println(map.get(entry.getKey()+"New").get(i));                       

           }    

}

My JSTL code till now:

<c:forEach items="${theList}" var="entry" varStatus="i">
                <tr>
                    <td>${entry.key}</td>

                    <c:forEach items="${entry.value}" var="item" varStatus="j">                             
                                <td>value:  ${entry.value[j.index]}</td>
                                 <td>What to Do here!</td>                          
                    </c:forEach>
                </tr>
</c:forEach>  
1

There are 1 best solutions below

0
On BEST ANSWER

sorry, Figured it out. Here's the solution.

<c:forEach items="${rmqList}" var="entry" varStatus="i">
                    <c:set var="editedfieldkey" value="${entry.key}New"/>
                <tr>
                        <td>${entry.key}</td>


                        <c:forEach items="${entry.value}" var="item" varStatus="j">
                            <c:if test="${item ne null }">      
                                <td>Value: ${item} <td>
                                <td>Edited Value ${rmqList[editedfieldkey][j.index]}</td>
                            </c:if>
                        </c:forEach>
                    </tr>
                </c:forEach>