HashMap with multiple values under the same key

2018-12-31 16:42发布

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 implement the storage of three values with one as the key?

标签: java
19条回答
看淡一切
2楼-- · 2018-12-31 17:08

Try LinkedHashMap, sample:

Map<String,String> map = new LinkedHashMap<String,String>();    
map.put('1','linked');map.put('1','hash');    
map.put('2','map');map.put('3','java');.. 

output:

keys: 1,1,2,3

values: linked,hash, map, java

查看更多
登录 后发表回答