Interface ListMultimap<K,V>

Type Parameters:
K - key type | 键类型
V - value type | 值类型
All Superinterfaces:
Multimap<K,V>

public interface ListMultimap<K,V> extends Multimap<K,V>
ListMultimap - List-based Multimap Interface ListMultimap - 基于列表的多值映射接口

A multimap that stores values in lists, preserving insertion order and allowing duplicate key-value pairs.

将值存储在列表中的多值映射,保留插入顺序并允许重复的键值对。

Features | 主要功能:

  • Duplicate values per key - 每个键允许重复值
  • Preserves insertion order - 保留插入顺序
  • List access to values - 列表方式访问值

Usage Examples | 使用示例:

ListMultimap<String, Integer> multimap = MultimapBuilder.linkedHashKeys()
    .arrayListValues()
    .build();

multimap.put("a", 1);
multimap.put("a", 2);
multimap.put("a", 1); // duplicate allowed

List<Integer> values = multimap.get("a"); // [1, 2, 1]

Performance | 性能特性:

  • get: O(1) - get: O(1)
  • put: O(1) amortized - put: O(1) 均摊

Security | 安全性:

  • Thread-safe: No (interface, implementation-dependent) - 否(接口,取决于实现)
  • Null-safe: No - 否
Since:
JDK 25, opencode-base-collections V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • get

      List<V> get(K key)
      Get the list of values for a key. 获取键对应的值列表。
      Specified by:
      get in interface Multimap<K,V>
      Parameters:
      key - the key | 键
      Returns:
      the list of values | 值列表
    • removeAll

      List<V> removeAll(Object key)
      Remove all values for a key and return them as a list. 移除键的所有值并以列表形式返回。
      Specified by:
      removeAll in interface Multimap<K,V>
      Parameters:
      key - the key | 键
      Returns:
      the removed values | 被移除的值
    • replaceValues

      List<V> replaceValues(K key, Iterable<? extends V> values)
      Replace all values for a key and return the old values as a list. 替换键的所有值并以列表形式返回旧值。
      Specified by:
      replaceValues in interface Multimap<K,V>
      Parameters:
      key - the key | 键
      values - the new values | 新值
      Returns:
      the old values | 旧值