You can roll your own by using a Map
Map<YourKeyClass, List<Data>> someStructure
= new HashMap<YourKeyClass, List<Data>>();
To your desired situation, looks like you need:
Map<YourKeyClass, List<List<Data>>> someStructure
= new HashMap<YourKeyClass, List<List<Data>>>();
Here's a kickoff example of the structure:
class MyMapOfList<K, V> {
Map<K, List<V>> innerMap;
public MyMapOfListOfList() {
innerMap = new HashMap<K, V>();
}
public void put(K key, V value) {
List<V> list = innerMap.get(key);
if (list == null) {
list = new ArrayList<V>();
innerMap.put(key, list);
}
list.add(value);
}
}
And you may use it like this:
MyMapOfList<String, List<Data>> myMapOfList;
If you don't like to add/maintain the List
s internally in the Map
, you could use a structure from third party library like MultiMap
from Guava, which behaves more like you want/need.
More info: