ImmutableMap.of() workaround for HashMap in Maps?

前端 未结 5 782
独厮守ぢ
独厮守ぢ 2020-12-29 03:40

There are utility methods to create ImmutableMap like Immutable.of(Key, value) and its overload.

But such methods don\'t exist for

5条回答
  •  执笔经年
    2020-12-29 03:55

    ImmutableMap.of() returns a hash based immutable map without order.

    If you need ordered immutable map, ImmutableSortedMap.of() is a choice.

    ImmutableSortedMap provides methods such as firstKey(), lastKey(), headMap(K) and tailMap(K);

    Both classes provide copyOf(Map) method.

提交回复
热议问题