Stream中使用findFirst()方法取处理流中的第一个元素,并使用isPresent()方法判断是否为空 eg:标签:Stream,isPresent,findFirst,BureauName,jcbureau,first From: https://www.cnblogs.com/sensenh/p/17579667.html
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);