如何迭代List <map <string,object>&gt;在java中</map <string,object>

时间:2011-04-23 09:29:40

标签: java collections

我有一个List,其中包含一个我要迭代的地图

List<Map<String, Object>> featureService=featureSubscriptionDao.getUnsubscribedSevice();

我的dao方法是

@Override
public List<Map<String, Object>> getUnsubscribedSevice() {
    String sql="select * from tblservice where public='false'";
    return getJdbcTemplate().queryForList(sql);
}

任何帮助?

3 个答案:

答案 0 :(得分:11)

List<Map<String, Object>> featureServices = getUnsubscribedSevice();

for (Map<String, Object> featureService : featureServices) {
    for (Map.Entry<String, Object> entry : featureService.entrySet()) {
       System.out.println(entry.getKey() + ": " + entry.getValue());
    }
}

答案 1 :(得分:0)

在Java 8中,您只需执行

    featureService.forEach(service -> 
                service.forEach((k, v) -> System.out.println(k + ": " + v)
    );

答案 2 :(得分:0)

从地图列表中提取:-

for (Map<String, Object> objectMap : cal.getMap_formula()) {
                        objectMap.keySet();//method 1st
                        objectMap.containsKey("key_name");//method 2nd
                        objectMap.get("key_name");//method 3rd
                    }