日期:2014-05-20  浏览次数:20787 次

请问一个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中,也许这样可以解决你的需求哟!