LinkedHashmap的java JSTL更改密钥
我在JSP中有一个linkedHashmap
我想在某些条件下更改它的键,保持值不变。 怎么做
<c:forEach var="loop" items="${Courses}"
varStatus="pLoop">
<c:set var="pKey" value="${pKey+1}"/> <!-- value that needs to be set as new key -->
<fmt:parseNumber var="tempKey" integerOnly="true"
type="number" value="${loop.key}" />
<!--Normally key values are set like this in hashmap in jstl -->
<c:set target="${Courses}" property="${pKey}" value="something"/>
<!-- but I want to keep value intact, want to change only key -->
</c:forEach>
# 1 楼答案
在地图中,您不会更改关键点。将具有相同值的新密钥放入,然后删除旧密钥