public static void main(String[] args) {
List<String> resultList = new ArrayList<>();
for (int i = 0; i < 500; i++) {
resultList.add(null);
}
LinkedHashMap<String, List<String>> listLinkedHashMap = new LinkedHashMap<>();
List<String> a = Arrays.asList("a","b","c");
List<String> b = Arrays.asList("1","2","3");
List<String> c = Arrays.asList("A","B","C");
List<String> d = Arrays.asList("one","tow","three");
listLinkedHashMap.put("a",a);
listLinkedHashMap.put("b",b);
listLinkedHashMap.put("c",c);
listLinkedHashMap.put("d",d);
int keyIdx = 0;
for (Map.Entry<String, List<String>> entry : listLinkedHashMap.entrySet()) {
List<String> val = entry.getValue();
for (int i = 1; i <= val.size(); i++) {
int actIdx = (i * listLinkedHashMap.size()) - (listLinkedHashMap.size() - keyIdx);
resultList.set(actIdx, val.get(i - 1));
}
keyIdx = keyIdx + 1;
}
System.out.println(resultList);
}```
Map<String,List> 交错合并为List
最新推荐文章于 2024-03-12 15:53:17 发布
该代码段展示了如何在Java中创建一个LinkedHashMap,存储List<String>值,并进行复杂遍历和索引操作。它填充了一个ArrayListresult列表,然后根据LinkedHashMap的键值对进行计算和更新。
摘要由CSDN通过智能技术生成