Java 8 modify stream elements

前端 未结 4 1234
生来不讨喜
生来不讨喜 2020-12-24 14:26

I wanted to write pure function with Java 8 that would take a collection as an argument, apply some change to every object of that collection and return a new collection aft

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-24 14:43

    Streams are immutable like strings so you cannot get around needing to create a new stream/list/array

    That being said you can use .Collect() to return a new collection post change so

    List result = inList.stream().map().Collect()
    

提交回复
热议问题