Java 8 collector for Guava immutable collections?

前端 未结 5 2238
花落未央
花落未央 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 10:09

    Since version 21, you can

    .collect(ImmutableSet.toImmutableSet())
    .collect(ImmutableMap.toImmutableMap())
    .collect(Maps.toImmutableEnumMap())
    .collect(Sets.toImmutableEnumSet())
    .collect(Tables.toTable())
    .collect(ImmutableList.toImmutableList())
    .collect(Multimaps.toMultimap(...))
    

提交回复
热议问题