Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Your code is bad formed here:</p> <pre><code>while(iterator.hasNext()){ hashMap.values().toArray(); for (???) { // lets print array here for example } } </code></pre> <p>You try to iterate using the Iterator "iterator" but next you call to </p> <pre><code>hashMap.values().toArray(); </code></pre> <p>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 <code>List&lt;String[]&gt; or List&lt;List&lt;String&gt;&gt;</code>.</p> <pre><code>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&lt;String,String[][]&gt; map= new HashMap&lt;String,String[][]&gt;(); map.put("layer1", layer1); Iterator&lt;Entry&lt;String, String[][]&gt;&gt; iterator = map.entrySet().iterator(); while(iterator.hasNext()){ Entry&lt;String, String[][]&gt; entry = iterator.next(); System.out.println("Key:" + entry.getKey()); String[][] value = entry.getValue(); for(int x=0;x&lt;value.length;x++){ for(int y=0;y&lt;value[x].length;y++){ System.out.println("String[" + x + "][" + y + "]:" + value[x][y]); } } } } </code></pre> <p>Also you can use "for each" loop to simplify the code insted using the "while":</p> <pre><code>for (Entry&lt;String, String[][]&gt; entry : map.entrySet()){ System.out.println("Key:" + entry.getKey()); String[][] value = entry.getValue(); for(int x=0;x&lt;value.length;x++){ for(int y=0;y&lt;value[x].length;y++){ System.out.println("String[" + x + "][" + y + "]:" + value[x][y]); } } } </code></pre> <p>Or if you only need the values:</p> <pre><code>for (Entry&lt;String, String[][]&gt; entry : map.values()){ String[][] value = entry.getValue(); for(int x=0;x&lt;value.length;x++){ for(int y=0;y&lt;value[x].length;y++){ System.out.println("String[" + x + "][" + y + "]:" + value[x][y]); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload