嗨! try 使用此流,但我打开了NoSuchElementException

var scores = findAllByBarcode
                .stream()
                .iterator()
                .next()
                        .getMpProductFeedbacks()
                                .stream()
                                        .filter(mpProductFeedback -> mpProductFeedback.getId()==mpProductFeedbackId)
                                               .iterator()
                .next()
                .getMpPersonScores()
                .stream()
                .map(mpPersonScore -> {
                            var score = new ScoreType();
                            score.setUserScore(mpPersonScore.getMpPersonScore());
                            score.setUser(mpPersonScore.getMpPersonLogin());
                            score.setUserComment(mpPersonScore.getMpPersonComment());
                            return score;
                })
    .toList();

部件后出现异常

filter(mpProductFeedback -> mpProductFeedback.getId()==mpProductFeedbackId)
                                           .iterator()
            .next()

try 使用orElse,但它只能与.equals一起使用 我已经有了==在两只长龙之间.

推荐答案

假设我们正在处理嵌套集合

List<ScoreType> scores = findAllByBarcode
    .stream()
    .map( b -> b.getMpProductFeedbacks() )
    .flatMap( Collection::stream )
    .filter( feedback -> feedback.getId() == mpProductFeedbackId )
    .map( feedback -> feedBack.getMpPersonScores() )
    .flatMap( Collection::stream )
    .map( personScore -> {
        ScoreType score = new ScoreType();
        score.setUserScore( personScore.getMpPersonScore() );
        score.setUser( personScore.getMpPersonLogin() );         
        score.setUserComment( personScore.getMpPersonComment() );
        return score;
    })
   .toList();

Java相关问答推荐

在Spring Boot中测试时出现SQL语法错误

为什么接口中的主函数而不是类中的主函数在Java 17中编译和运行没有问题?

Java事件系统通用转换为有界通配符

在for—each循环中的AnimationTimer中的if语句'

如何创建同一类的另一个对象,该对象位于变量中?

为什么在maven中,getLast方法不适用于List?

在Spring Boot中使用哪个Java类来存储创建时间戳?

按属性值从流中筛选出重复项

每次FXMLLoader调用ApplationConext.getBean(类)时创建@Component的新实例

Docker不支持弹性APM服务器

如何在Cosmos DB(Java SDK)中增加默认响应大小

如何在JavaFX中制作鼠标透明stage

Java Telnet客户端重复的IAC符号

如何在EL处理器中定义带有命名空间的变量?

对从Spring Boot 3.1.5升级到3.2.0的方法的查询验证失败

对角线填充二维数组

TinyDB问题,无法解析符号';上下文&

这是JavaFX SceneBuilder的错误吗?

@此处不能应用可为null的批注

语句打印在错误的行(Java Token 问题)