What is an efficient and elegant way to add a single element to an immutable set?

后端 未结 7 822
谎友^
谎友^ 2020-12-29 21:40

I have an immutable set (cast as a Set) that potentially contains many elements. I need a Collection that contains the elements from that set plu

7条回答
  •  离开以前
    2020-12-29 22:10

    I'm experiencing cognitive dissonance when I read "immutable" and "add to" in the same sentence. You can add a new element to the end of a mutable copy of the immutable values, but you can't modify the immutable set. I don't know of anything elegant.

提交回复
热议问题