首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

请教一个Map集合的有关问题.

2012-09-24 
请问一个Map集合的问题..我有一个需求,需要以key value形式进行存储...有什么办法 可以让 map 的key重复,

请问一个Map集合的问题..
我有一个需求,需要以key value形式进行存储...

有什么办法 可以让 map 的key重复,并且 允许NullKey nullValue呢????????

在线等,,或者有更好的办法,要code,或者清晰的思路,Thank!!!!!!!!!!!!












在线等,

[解决办法]
public class MyMapList{
private List<MyMap> mapList = new ArrayList<MyMap>{} 

}
private class MyMap{
private String key;
private String value;
}
[解决办法]
可以使用google guava 提供的 Multimap
put
boolean put(@Nullable
K key,
@Nullable
V value)
Stores a key-value pair in the multimap. 

Some multimap implementations allow duplicate key-value pairs, in which case put always adds a new key-value pair and increases the multimap size by 1. Other implementations prohibit duplicates, and storing a key-value pair that's already in the multimap has no effect. 

Parameters:
key - key to store in the multimap
value - value to store in the multimap 
Returns:
true if the method increased the size of the multimap, or false if the multimap already contained the key-value pair and doesn't allow duplicates
[解决办法]
给你个建议,你可以讲你需要的数据存入map中,map中的键值是不允许重复的,但set list中的数据可以重复,所以你可以将你添加的数据存入map中后,再存入到list中,也许这样可以解决你的需求哟!

热点排行
Bad Request.