ArrayList<String> objects = new ArrayList<>();
("a");("b");("c");("d");
(资料图)
// 列表转列表:直接toList
List<String> ans1 = ()
.filter(x -> ("a") || ("b"))
.collect(());
// 列表转map在最后toMap即可由String转Entry
Map<String, String> ans2 = ()
.filter(x -> ("c") || ("d"))
.collect((x -> x, x -> x + "1", (a, b) -> b));
// map转map也是在toMap做好映射关系
Map<String, String> ans3 = ().stream()
.filter(x -> ().equals("c"))
.collect((x -> (), x -> ()));
// map可以改元素Entry为String
List<String> ans4 = ().stream()
.filter(x -> ().equals("d"))
.map(x -> () + ())
.collect(());
("列表转列表" + ans1);
("列表转map" + ans2);
("map转map" + ans3);
("map转列表" + ans4);
标签: