Java 8 collector for Guava immutable collections?

前端 未结 5 2215
花落未央
花落未央 2020-12-17 09:55

I really like Java 8 streams and Guava\'s immutable collections, but I can\'t figure out how to use the two together.

For example, how do I implement a Java 8 Collec

5条回答
  •  离开以前
    2020-12-17 09:55

    Although it doesn't answer specifically the question, it's noteworthy to mention that this simple pattern can help everyone building Guava's immutable collections from streams without having the need for Collectors (as their implementations are rather hard to make).

    Stream stream = ...
    
    ImmutableXxx collection = ImmutableXxx.copyOf(stream.iterator());
    

提交回复
热议问题