java以及jstl表达式中对HashMap的迭代

    xiaoxiao2021-03-25  101

    ①Java

    entrySet()返回此映射所包含的映射关系的Set视图,即key-value的set集合,类型是Set<Map.Entry<K,V>>

    HashMap<String, Object> map = new HashMap<String, Object>(); map.put("001", "xy001"); map.put("002", "xy002"); Set<Map.Entry<String, Object>> entrySet = map.entrySet(); for (Map.Entry<String, Object> entry : entrySet) { System.out.println(entry.getKey() + "..." + entry.getValue()); }

     

    ②JSTL

    <c:forEach items="${map}" var="entry">  ${entry.key}:${entry.value} </c:forEach>

     

    转载请注明原文地址: https://ju.6miu.com/read-20823.html

    最新回复(0)