본문
convert list-map to map
프로그래밍/Java 2017. 4. 6. 10:35
반응형
# convert list-map to map
result2 (list-map)에서 map을 추출한 뒤, 추출한 map을 result (list-map)로 병합하는 로직
source)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | package com.aimir.schedule.task; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Test { public static void main(String[] args) { Map<String, Object> condition1 = new HashMap<String, Object>(); Map<String, Object> condition2 = new HashMap<String, Object>(); List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); List<Map<String, Object>> result2 = new ArrayList<Map<String, Object>>(); condition1.put("SYS_ID", "781"); condition1.put("RELATED_METER", "22"); condition1.put("NAME", "SSYS"); condition1.put("METERING_COUNT", "1"); result.add(condition1); condition2.put("SYS_ID", "782"); condition2.put("RELATED_METER", "1"); condition2.put("NAME", "SSYS"); condition2.put("METERING_COUNT", "0"); result2.add(condition2); System.out.println("result : " + result); System.out.println("result2 : " + result2); System.out.println("===="); int index = 0; for (Map<String, Object> map : result2) { for (Map.Entry<String, Object> entry : map.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); map.put(key,value); } index++; result.add(map); } System.out.println("result : " +result); } } | cs |
result)
1 2 3 4 | result : [{SYS_ID=781, RELATED_METER=22, NAME=SSYS, METERING_COUNT=1}] result2 : [{SYS_ID=782, RELATED_METER=1, NAME=SSYS, METERING_COUNT=0}] ==== result : [{SYS_ID=781, RELATED_METER=22, NAME=SSYS, METERING_COUNT=1}, {SYS_ID=782, RELATED_METER=1, NAME=SSYS, METERING_COUNT=0}] | cs |
반응형
댓글