Stream findFirst()

Stream中使用findFirst()方法取处理流中的第一个元素,并使用isPresent()方法判断是否为空 eg:
Optional<Jcbureau> first = appStartAfterRunner.getJCBUREAUS().stream().filter(s -> Objects.equals(s.getBureaucode(), bureauCode)).findFirst();
String BureauName = null;
if (first.isPresent()) {
Jcbureau jcbureau = first.get();
BureauName = jcbureau.getBureauname();
}
ret.setBureauName(BureauName);
posted @ 2023-07-25 13:30  sensen~||^_^|||&  阅读(256)  评论(0)    收藏  举报