简体   繁体   English

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

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

I have an hashmap savedQuestionAnswer with Integer as key and ArrayList as value in the following code 我在以下代码中保存了一个哈希表,其中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>

I am trying to print a questionnaire with multiple answers . 我正在尝试打印具有多个答案的问卷。 So for each question (present in questionName) I have saved the list of answer in the hash map savedQuestionAnswer with corresponding index value . 因此,对于每个问题(在questionName中存在),我都将答案列表保存在哈希表savedQuestionAnswer并带有相应的索引值。

I am getting a syntax error, 我收到语法错误,

"The function longValue must be used with a prefix when a default namespace is not specified". “未指定默认名称空间时,必须将函数longValue与前缀一起使用”。

Not able to get what is the correct syntax or way to accomplish it 无法获得正确的语法或完成方法

LoopTagStatus.getCount() returns int. LoopTagStatus.getCount()返回int。 Why do you need: 为什么你需要:

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

Try simply 简单尝试

${savedQuestionAnswer[theCount.count]}

Also note that 另请注意

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

so depending on how you populate your HashMap, you should use 因此,根据您填充HashMap的方式,应使用

theCount.index theCount.index

or 要么

theCount.count theCount.count

as a key. 作为关键。

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

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