Tag Archives: Map

java 8 의 컬렉션(Map, Set, List…)을 편리하게 순회하는 샘플코드 (forEach, replaceAll, filter, map…)

By | 3월 25, 2021

/* * 기본적인 루프 * – map.forEach() */ map.forEach((k, v) -> System.out.println("key: " + k + ", value: " + v)); map.forEach((k,v) -> { System.out.println("key: " + k + ", value: " + v) }); map.entrySet().forEach((e) -> System.out.println("key: " + e.getKey() + ", value: " + e.getValue())); map.keySet().forEach((k) -> System.out.println("key: " + k)); map.values().forEach((v) ->… Read More »

Java Map 내의 요소 정렬(sort)하는 코드 샘플

By | 9월 16, 2019

private Map<String, OwnerVO> getSortedMapByOwnerTotChgVol(Map<String, OwnerVO> ownerMap) { List<Map.Entry<String, OwnerVO>> sortList = new LinkedList<>(ownerMap.entrySet()); Collections.sort(sortList, new Comparator<Map.Entry<String, OwnerVO>>() { @Override public int compare(Entry<String, OwnerVO> o1, Entry<String, OwnerVO> o2) { return ((o1.getValue().getTotChgVol() – o2.getValue().getTotChgVol()) < 0 ? 1 : -1); } }); Map<String, OwnerVO> sortedMap = new LinkedHashMap<>(); Iterator<Map.Entry<String, OwnerVO>> iter = sortList.iterator(); while(iter.hasNext()) { Map.Entry<String, OwnerVO>… Read More »