Reputation: 7
I am basically trying to create the data structre
Map<String, Map<String, List<String>>>
I have a map as shown below in which there is a key and values are of type List
:
Map<String, List<String> newdatamap = new HashMap<>();
map.put ("payerName", Arrays.asList("wpn", "wpfnb", "dgeft", "xbthy"));
map.put ("fixedRate", Arrays.asList("dd", "ww", "trrty", "httyure"))
I'd like to add another map over the previous map, such that there is a key and its value will be the above map. Is this the correct data structure, and how do we implement it?
I want something like this shown below
Key Value
B1 payerName ----> "wpn", "wpfnb", "dgeft", "xbthy"
fixedRate ----->"dd", "ww", "trrty", "httyure"
B2 payerName ----> "SSSwpn", "wpfSSSnb", "GGGdgeft", "xbtYYYYhy"
fixedRate ----->"WWdd", "wTTYw", "YYYYtrrty", "IIIhttyure"
As shown above, only a new key has been introduced to the map, and its value is the previous map. So please advise how to create such map
Map<String, Map<String, List<String>>>.
Well I have tried through Google guava library I have shown below but I want to achieve same through java itself. Please advise how can i achieve the same through java
final Table<String, String, List<String>> values = HashBasedTable.create();
values.put("B1", "payerName", Lists.newArrayList("wpn", "wpfnb", "dgeft", "xbthy"));
System.out.println(values.get("B1", "payerName")); // prints the list
Upvotes: 1
Views: 80
Reputation: 4662
It's beyond the scope of the question, but as OP asked me in the comment I'm answering here:
class Info {
public final String payerName;
public final String fixedrate;
public Info(String pn, String fr) {
payerName = pn;
fixedRate = fr;
}
}
[...]
Collection<Info> myInfo = new LinkedList<>();
myInfo.add(new Info("wpn", "dd"));
myInfo.add(new Info("wpfnb", "ww"));
myInfo.add(new Info("dgeft", "trrty"));
myInfo.add(new Info("xbthy", "httyure"));
Map<String, Collection<Info>> myData = new HashMap<>();
myData.put("B1", myInfo);
Upvotes: 0
Reputation: 1863
Few more details to the answer of assylias
Map<String, Map<String, List<String>>> ultimateMap = new HashMap<String,Map<String, List<String>>> ();
Map<String, List<String>> map1 = new HashMap<String, List<String>>();
map1.put ("payerName", Arrays.asList("wpn", "wpfnb", "dgeft", "xbthy"));
map1.put ("fixedRate", Arrays.asList("dd", "ww", "trrty", "httyure"));
Map<String, List<String>> map2 = new HashMap<String, List<String>>();
map2.put ("payerName", Arrays.asList("SSSwpn", "wpfSSSnb", "GGGdgeft", "xbtYYYYhy"));
map2.put ("fixedRate", Arrays.asList("WWdd", "wTTYw", "YYYYtrrty", "IIIhttyure"));
ultimateMap.put("B1", map1);
ultimateMap.put("B2", map2);
I could not add it as a comment to the previous answer (too long). So added as a new answer.
Upvotes: 1
Reputation: 328923
You are almost there:
Map<String, Map<String, List<String>>> map = new HashMap<> ();
map.put("B1", newdatamap);
Upvotes: 1