繁体   English   中英

如何遍历哈希表,将值作为给定索引的数组列表

[英]How to iterate through a hashmap with value as an arraylist for a given index

我在以下代码中保存了一个哈希表,其中Integer作为键,而ArrayList作为值

<c:set var="form" value="${surveyQuestionnaire}"/>
    <c:forEach var="questionName" items="${form.questionsList }"  varStatus="theCount">
 Q.<c:out value="${questionName}"></c:out>
<c:forEach items="${savedQuestionAnswer[(theCount.count).longValue()]}" var="choice" varStatus="choiceStatus">
       <br/> ${choiceStatus.count})${choice} 
     </c:forEach> <br/>
</c:forEach>

我正在尝试打印具有多个答案的问卷。 因此,对于每个问题(在questionName中存在),我都将答案列表保存在哈希表savedQuestionAnswer并带有相应的索引值。

我收到语法错误,

“未指定默认名称空间时,必须将函数longValue与前缀一起使用”。

无法获得正确的语法或完成方法

LoopTagStatus.getCount()返回int。 为什么你需要:

${savedQuestionAnswer[(theCount.count).longValue()]}

简单尝试

${savedQuestionAnswer[theCount.count]}

另请注意

  • LoopTagStatus.getCount()从1开始计数
  • LoopTagStatus.getIndex()从0开始计数

因此,根据您填充HashMap的方式,应使用

theCount.index

要么

theCount.count

作为关键。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM