How to iterate nested lists with lambda streams?

前端 未结 6 1829
眼角桃花
眼角桃花 2021-02-12 20:16

I\'m trying to refactor the following code to lambda expressions with `stream, especially the nested foreach loops:

public static Result match (Response rsp) {
          


        
6条回答
  •  离开以前
    2021-02-12 20:33

    Try to use map which transform the original source.

       rsp.getFirstNodes().stream().map(FirstNode::getSndNodes)
                   .filter(sndNode-> sndNode.isValid())
                   .forEach(sndNode->{
       // No do the sndNode parsing operation Here.
       })
    

提交回复
热议问题