HashMap with multiple values under the same key

前端 未结 22 1841
旧时难觅i
旧时难觅i 2020-11-22 06:49

Is it possible for us to implement a HashMap with one key and two values. Just as HashMap?

Please do help me, also by telling (if there is no way) any other way to

22条回答
  •  盖世英雄少女心
    2020-11-22 07:09

    Take a look at Multimap from the guava-libraries and its implementation - HashMultimap

    A collection similar to a Map, but which may associate multiple values with a single key. If you call put(K, V) twice, with the same key but different values, the multimap contains mappings from the key to both values.

提交回复
热议问题