title: Looping array of only two object to assign to the Map?
body: <p>I was trying to work on an example to loop the array of objects which are only just two objects, and getting the values to assign it to the map by the setting key and the values fetched from the array object. How can i differentiate the object 1 and object 2 from the array to go in the map1 and map2 object? I want the values of array with index 0 object to in map1 and the other array with index 1 in the other map. </p>
  
  <pre><code>Map&lt;String,String&gt; map1 = new HashMap&lt;String,String&gt;();
  Map&lt;String,String&gt; map2 = new HashMap&lt;String,String&gt;();
  
  for(MyArray obj : actualArray){
  
  //how can i the object 1 and object 2 from the array and assign it to the map1 for object1 values and map2 for object2 values.??
  
  }
  </code></pre>
  
  <p>I was trying below way instead of looping which is throwing arrayOutOfBoundException if any of the either objects is not available;</p>
  
  <pre><code>map1.put("firstName", myArray[0].getFirstName());
  map1.put("firstName", myArray[0].getLasttName());
  
  map2.put("firstName", myArray[1].getFirstName());
  map2.put("firstName", myArray[1].getLasttName());
  </code></pre>
  
  <p>I tried to find some solutions and examples online but no luck, any suggestions and help will be appreciated as am new in java programming. </p>