对于2个List<Map<>> 的操作可以调用forEach 和BiConsumer进行处理
getBiconsumer
是返回BiConsumer
的高阶函数, 并采用.accept()
进行调用
public static void printWithConsumer(Map<String, String> map1, Map<String, String> map2, BiConsumer<String, String> consumer) {
BiConsumer<Map<String, String>, Map<String, String>> biConsumer = getBiConsumer(consumer);
biConsumer.accept(map1, map2);
}
//返回BiConsumer,用以消费2个Map
private static BiConsumer<Map<String, String>, Map<String, String>> getBiConsumer(BiConsumer<String, String> consumer) {
return (map1, map2) -> {
map1.forEach(consumer);
map2.forEach(consumer);
};
}
public static void printWithComma(Map<String, String> map1, Map<String, String> map2) {
printWithConsumer(map1, map2, (k, v) -> System.out.println(k + "," + v));
}