본문 바로가기
Backend/JAVA

[JAVA] List map에서 데이터 가져오기

by couque 2023. 4. 30.
반응형

List Map에서 데이터 가져오기

Map<String, Object> map = new HashMap<String, Object>();
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

map.put("one", "1");
map.put("two", "2");
map.put("three", "3");

list.add(map);

for(int i = 0; i < list.size(); i++){
    System.out.println("list 사이즈 :" + i);
    System.out.println("list entrySet :" + list.get(i).entrySet());
    
    for( Map.Entry<String, Object> elem : list.get(i).entrySet() ){
        // list 각각 hashmap받아서 출력
       if(elem.getValue() != null && elem.getValue() != "") {
           System.out.println("키 : " + elem.getKey() + ", 값:" + elem.getValue());
       }
    }
}

for(Map a : list){
	System.out.println("a : " + a);
}
반응형

댓글