我怎样才能从字典中获取arraylist

时间:2014-03-14 10:08:23

标签: java jsp

我正在开展一个小项目并且我被困在这一行当前我的代码就像

<% for (int j = 0; j < list1.Count; j++)
{
    foreach(Dictionary<string , string> itemLists in list1)
    {
    Response.Write( itemLists["image"] );
    }
} 
%>

我无法做到

foreach(Dictionary<string , string> itemLists in list[i])
{
Response.Write( itemList["image"] );
}

1 个答案:

答案 0 :(得分:0)

Dictionary是C#数据结构(以及属性Count of List) - 在Java中,要实现你想要的,你会使用Map的一些实现(f.e.HashMap):

for (Map.Entry<String, Object> entry : map.entrySet()) {
    String key = entry.getKey();
    Object value = entry.getValue();
}

出于某种原因,您似乎想要使用地图列表,因此请尝试:

<% for (int j = 0; j < mapList.size(); j++) {
    for (final Map<String, String> map : mapList) {
        Response.Write(map.get("image"));
    }
} %>

当然,它会提前准备这样的结构。看看你的问题中的错误类型,我强烈建议你去阅读基础JSP的手册(可能还有一些Java的介绍)。