Stream中findAny

2022-12-05 10:46:36 1 举报
Stream<Author> stream = getAuthors().stream(); Stream<Author> stream1 = stream.filter(author -> author.getAge() > 40); Stream<String> stream2 = stream1.map(new Function<Author, String>() { @Override public String apply(Author author) { return author.getName(); } }); Optional<String> stream2Any = stream2.findAny(); String name = stream2Any.orElseGet(() -> "佚名"); System.out.println(name);
流程图
stream java8
作者其他创作
大纲/内容
评论
0 条评论
下一页