Class ImmutableMultimap.Builder<K,​V>

  • Direct Known Subclasses:
    ImmutableListMultimap.Builder, ImmutableSetMultimap.Builder
    Enclosing class:
    ImmutableMultimap<K,​V>

    @DoNotMock
    public static class ImmutableMultimap.Builder<K,​V>
    extends Object
    A builder for creating immutable multimap instances, especially public static final multimaps ("constant multimaps"). Example:
    
     static final Multimap<String, Integer> STRING_TO_INTEGER_MULTIMAP =
         new ImmutableMultimap.Builder<String, Integer>()
             .put("one", 1)
             .putAll("several", 1, 2, 3)
             .putAll("many", 1, 2, 3, 4, 5)
             .build();
     

    Builder instances can be reused; it is safe to call build() multiple times to build multiple multimaps in series. Each multimap contains the key-value mappings in the previously created multimaps.

    Since:
    2.0