【发布时间】:2015-11-03 19:15:48
【问题描述】:
在 Java8 中,我有一个流,我想应用一个 映射器流。
例如:
Stream<String> strings = Stream.of("hello", "world");
Stream<Function<String, String>> mappers = Stream.of(t -> t+"?", t -> t+"!", t -> t+"?");
我想写:
strings.map(mappers); // not working
但我目前解决任务的最佳方式是:
for (Function<String, String> mapper : mappers.collect(Collectors.toList()))
strings = strings.map(mapper);
strings.forEach(System.out::println);
我该如何解决这个问题
- 不将映射器收集到列表中
- 不使用
for循环 - 不破坏我流畅的代码
【问题讨论】:
标签: java functional-programming java-8 java-stream