Your code is bad formed here:
while(iterator.hasNext()){ hashMap.values().toArray(); for (???) { // lets print array here for example } }
You try to iterate using the Iterator "iterator" but next you call to
hashMap.values().toArray();
To get the next item of the loop you need to use iterator.next(); to fetch it. Also is good to change the "Object" by String[][] or to List<String[]> or List<List<String>>.
import java.util.HashMap; import java.util.Map; import java.util.Iterator; import java.util.Map.Entry; public static void main(String[] args) { String[][] layer1 = { {"to1", "TYPE1", "start"}, {"to2", "TYPE1", "start"} }; Map<String,String[][]> map= new HashMap<String,String[][]>(); map.put("layer1", layer1); Iterator<Entry<String, String[][]>> iterator = map.entrySet().iterator(); while(iterator.hasNext()){ Entry<String, String[][]> entry = iterator.next(); System.out.println("Key:" + entry.getKey()); String[][] value = entry.getValue(); for(int x=0;x<value.length;x++){ for(int y=0;y<value[x].length;y++){ System.out.println("String[" + x + "][" + y + "]:" + value[x][y]); } } } }
Also you can use "for each" loop to simplify the code insted using the "while":
for (Entry<String, String[][]> entry : map.entrySet()){ System.out.println("Key:" + entry.getKey()); String[][] value = entry.getValue(); for(int x=0;x<value.length;x++){ for(int y=0;y<value[x].length;y++){ System.out.println("String[" + x + "][" + y + "]:" + value[x][y]); } } }
Or if you only need the values:
for (Entry<String, String[][]> entry : map.values()){ String[][] value = entry.getValue(); for(int x=0;x<value.length;x++){ for(int y=0;y<value[x].length;y++){ System.out.println("String[" + x + "][" + y + "]:" + value[x][y]); } } }