title: How to save integers from map to using the for loop
body: <p>I have a question to you, I am trying to save integers from map to an array using for loop. This example below is not working as I wanted, because when I display that array of ints it only have '2' for 10 elements, but I wanted to get [1,2,0,0,0,0...], what should be changed in that code?</p>
  
  <pre><code>Map&lt;Integer, String&gt; fooMap = new HashMap&lt;&gt;();
  fooMap.put(1, "AB");
  fooMap.put(2, "BBA");
  
  int[] arrayOfIntegers = new int[10];
  
  for (Map.Entry&lt;Integer, String&gt; values : fooMap.entrySet()) {
      int val = values.getKey();
      System.out.println(val);
      for (int index = 0; index &lt; arrayOfIntegers.length; index++) {
          arrayOfIntegers[index] = val;
      }
  }
  </code></pre>