Code example for ImmutableMultimap.Builder

Methods: build, put, putAll

   public static <K, V> Multimap<K, V> replaceValue(Multimap<K, V> fromMultimap, final K key, final V value) {
      checkNotNull(fromMultimap, "input multimap");
      checkNotNull(key, "key");
      checkNotNull(value, "value");
      return ImmutableMultimap.<K, V>builder()
                              .putAll(withoutKey(fromMultimap, key))
                              .put(key, value).build();
   public static <K, V> Multimap<K, V> replaceEntries(Multimap<K, V> fromMultimap, Multimap<K, V> updates) {
      checkNotNull(fromMultimap, "input multimap");
      checkNotNull(updates, "updates");
      return ImmutableMultimap.<K, V>builder()
                              .putAll(withoutKeys(fromMultimap, updates.keySet()))
   public static <K, V> Multimap<K, V> withoutKey(Multimap<K, V> fromMultimap, K key) {
      return Multimaps.<K, V> filterKeys(fromMultimap, Predicates.not(Predicates.equalTo(key)));
   public static <K, V> Multimap<K, V> withoutKeys(Multimap<K, V> fromMultimap, Set<K> keys) {
      return Multimaps.<K, V> filterKeys(fromMultimap, Predicates.not(;
    * change the keys but keep the values in-tact. 
    * @param <K1> 
    *           input key type 
    * @param <K2> 
    *           output key type 
    * @param <V> 
    *           value type 
    * @param in 
    *           input map to transform 
    * @param fn 
    *           how to transform the values 
    * @return immutableMap with the new keys. 
   public static <K1, K2, V> Multimap<K2, V> transformKeys(Multimap<K1, V> in, Function<K1, K2> fn) {
      checkNotNull(in, "input map");
      checkNotNull(fn, "function");
      Builder<K2, V> returnVal = ImmutableMultimap.builder();
      for (Entry<K1, V> entry : in.entries())
         returnVal.put(fn.apply(entry.getKey()), entry.getValue());
Contextual code suggestions in your IDE  Get Codota for Java