// "Replace 'compute' with 'computeIfPresent'" "true-preview" import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; class Main { interface Item { Integer getInfo(int i); } native List getNamesList(); void test(List infoList) { Map> data = new HashMap<>(); List names = getNamesList(); for (String key : names) { data.put(key, new ArrayList<>()); } for (Item info : infoList) { for (int i = 0; i < names.size(); i++) { final String k = names.get(i); final Integer newValue = info.getInfo(i); data.compute(k, (key, array) -> { array.add(newValue); return array; }); } } } }