Java 8 stream join and return multiple values

后端 未结 4 1422
时光说笑
时光说笑 2020-12-17 22:32

I\'m porting a piece of code from .NET to Java and stumbled upon a scenario where I want to use stream to map & reduce.

class Content
{
  private String          


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-17 23:04

    You can use proper lambda for BinaryOperator in reduce function.

    Content c = contentList
                .stream()
                .reduce((t, u) -> new Content(
                                      t.getA() + ',' + u.getA(),
                                      t.getB() + ',' + u.getB(), 
                                      t.getC() + ',' + u.getC())
                       ).get();
    

提交回复
热议问题