Get the key and value of Map that is used Inside another Map (JAVA)
Posted
by
Umair Iqbal
on Stack Overflow
See other posts from Stack Overflow
or by Umair Iqbal
Published on 2013-11-09T15:16:41Z
Indexed on
2013/11/09
15:54 UTC
Read the original article
Hit count: 269
I am using a map inside another map, The key of the outer map is Integer and the value is another Map. I get the values as expected but I don't know how to get the key and value of teh inner map. Here is the code
Map<Integer, Map<Integer, Integer>> cellsMap = new HashMap<Integer, Map<Integer, Integer>>();
Map<Integer , Integer> bandForCell = cellsMap.get(band_number);
if (bandForCell == null)
bandForCell = new HashMap<Integer, Integer>();
bandForCell.put(erfcn, cell_found);
cellsMap.put(band_number, bandForCell);
csv.writeCells((Map<Integer, Map<Integer, Integer>>) cellsMap);
public void writeCells (Map<Integer, Map<Integer, Integer>> cellsMap ) throws IOException
{
for (Map.Entry<Integer, Map<Integer, Integer>> entry : cellsMap.entrySet()) {
System.out.println("Key: " + entry.getKey() + ". Value: " + entry.getValue() + "\n");
}
}
Out put of my Map
Key: 20 Value: {6331=0, 6330=1, 6329=1, 6328=0, 6335=1, 6437=0, 6436=1}
The value in the above output is another map. How can I get the key and value of the inner map from the value of the outer map?
Like Keys of inner map = 6331, 6330, 6329 .... and values of inner map = 0 , 1 , 1 , 0 ...
Thanks
© Stack Overflow or respective owner