如何遍历嵌套Map<Integer, List<abc>>
Class Abc {
int id ;
String name;
Date startDate;
int rowNum;
}
List<Abc> dupList = list
.stream()
.collect(Collectors.groupingBy(Abc::getRowNum))
.values()
.stream()
.filter(v-> v.size()>=2)
.flatMap(List::stream)
.collect(Collectors.toList());
Map<Integer, List<Abc>> byRows = dupList
.stream()
.collect(Collectors.groupingBy(Abc::getRowNum));
Map contains fallowing data
Key value(abc List)
rowNum: 1 rowNum: 1
startDate: 01/01/2019
endDate:12/31/2099
name: Test1
Id:101
rowNum: 1 rowNum: 1
startDate: 01/01/2020
endDate:12/31/2099
name: Test1
Id:111
rowNum: 3 rowNum: 3
startDate: 01/01/2020
endDate:12/31/2099
name: Test4
Id:342
rowNum: 3 rowNum: 3
startDate: 01/01/2020
endDate:12/31/2099
name: Test4
Id:348
现在我想打印键的值和相应的 Abc 类列表。
当我尝试打印地图时
Map<Integer, List<Abc>> collect = byRows
.entrySet()
.stream()
.collect(Collectors.toMap(Map.Entry::getKey,
Map.Entry::getValue));
System.out.println(collect);
我正在获取输出,因为{1=[Abc@1d72673f, Abc@1cffb7e0], 3=[Abc@522530e9, Abc@58dc69f2]} 我没有从 Abc 类的 ArrayList 的嵌套循环中获取实际值。
预期输出:
I want to print startDate for each all rows
Ex: rowNum startDate
1 01/01/2019 {startDate}
01/01/2020
3 startDate: 01/01/2020
startDate: 01/01/2020
守着星空守着你
慕村225694
相关分类