Java collection/map apply method equivalent?

后端 未结 8 481
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 19:27

I would like to apply a function to a Java collection, in this particular case a map. Is there a nice way to do this? I have a map and would like to just run trim() on all t

8条回答
  •  囚心锁ツ
    2020-12-13 20:28

    Whether you can modify your collection in-place or not depends on the class of the objects in the collection.

    If those objects are immutable (which Strings are) then you can't just take the items from the collection and modify them - instead you'll need to iterate over the collection, call the relevant function, and then put the resulting value back.

提交回复
热议问题