what java collection that provides multiple values for the same key

后端 未结 3 963
清歌不尽
清歌不尽 2021-01-03 00:58

what type of java collection that returns multiple values for the same key?

example, I want to return 301,302,303 for key 300.

3条回答
  •  耶瑟儿~
    2021-01-03 01:26

    1. As mentioned in a comment above above there is always Guava Multimap
      http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Multimap.html

    2. Apache Commons Collections 4 has Generic version of MultiMap http://commons.apache.org/proper/commons-collections/apidocs/org/apache/commons/collections4/MultiMap.html

    3. JAX-RS specifies a MultivaluedMap interface which is implemented by all JAX-RS Providers. If your use case is within the context of a JAX-RS REST Service/Client, it would be an option to use their implementation without pulling in another dependency.

      javax.ws.rs.core.MultivaluedMap (each JAX RS Provider has their own implementation)

提交回复
热议问题