4

I have one List which contain one map i want to iterate is

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

my dao method is

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

any help ?

3 Answers 3

12
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());
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

As opposed to corgraths solution, note how this one uses entryset instead of keyset to get the keys and values. This is better because one doesn't have to use get on the map (using the keys) to get the values (saving some time)
0

In Java 8 you can simply use a lambda function.

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

Comments

0

Extract from the lists of the map:-

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.