title: Parsing values in hashmap of type List in java for JTable
body: <pre><code>HashMap&lt;Integer, List&lt;MyFields&gt;&gt; hmapp = new HashMap&lt;&gt;();
  </code></pre>
  <p>I have a form which is filled by a user, each user has a keyID assigned to them that they must enter when filling in the text fields. There are a total of 4 text fields that they can answer excluding the text field containing the keyID.</p>
  <p>If the same user submits the same text field values, the list does not change. If the user submits different form values, this is then added to the list for that keyID.</p>
  <p>Example:<Br>
  keyID: 123<br>
  firstField: cat<br>
  secondField: dog<br>
  thirdField: 43<br>
  fourthField: fish</p>
  <p>Hashmap will then equal:
  {123=[cat dog 43 fish]}</p>
  <p>If they submit the exact same thing, the hashmap will not change.</p>
  <p>If the next submission is for the same keyID with any field value different from the existing values, like so:<br>
  keyID: 123<br>
  firstField: cat<br>
  secondField: dog<br>
  thirdField: 43<br>
  fourthField: bird<br></p>
  <p>Then the hashmap will look like so:
  {123=[cat dog 43 fish,cat dog 43 bird]}</p>
  <p>Another example entry:
  keyID: 456<br>
  firstField: house<br>
  secondField: store<br>
  thirdField: 53<br>
  fourthField: shoes<br></p>
  <p>Then the hashmap will look like so:
  {123=[cat dog 43 fish, cat dog 43 bird], 456=[house store 53 shoes]}</p>
  <p>I populate a list with these keyID's, and when an item is selected on the list I fire an event to populate a JTable, which is of AbstractTableModel.</p>
  <p>There are four columns in the table pertaining to the four text fields.
  I want to populate the rows based on the list values.
  So if keyID 123 is selected, then row1 would be cat dog 43 fish, under the respective column. row2 would be cat dog 43 bird, under the respective column.</p>
  <p>How can I accomplish this?</p>
  <blockquote>
  <pre><code>private void formListValueChanged(javax.swing.event.ListSelectionEvent evt) {      
  
      try {
          int keyID = Integer.parseInt(formList.getSelectedValue());
          List&lt;MyFields&gt; lvals = hmapp.get(keyID);
  
          Object[] lvals2 = hmapp.get(keyID).toArray();
  
          AbsTable model = (AbsTable) formTable.getModel();
  
          for (int i = 0; i &lt; lvals.size(); i++) {
              Object[] row = new Object[3];
              for (int j = 0; j &lt; row.length; j++) {
                  row[j] = lvals;
              }
              System.out.println(lvals2.length);
              for (Object z : lvals2) {
                  System.out.println(z);
              }
  
          }
          Iterator&lt;MyFields&gt; objVals = lvals.iterator();
          while (objVals.hasNext()) {
              System.out.println(objVals.next());
          }
          
  
      } catch (NumberFormatException e) {
          System.out.println(&quot;Err: Null list selection.&quot;);
      }
  }
  
  
  
  
  private class AbsTable extends AbstractTableModel{
      
      private String[] vals;
      private final int NUM_COL = 4;
      public String[] colNames = new String[]{&quot;first&quot;, &quot;second&quot;, &quot;third&quot;, &quot;fourth&quot;};
      private final Class&lt;?&gt;[] colTypes = new Class&lt;?&gt;[]{String.class, String.class, Integer.class, String.class};
      
      public AbsTable(){
          vals=hmapp.keySet().toArray(new String[hmapp.size()]);
      }
      @Override
      public int getRowCount() {
          return hmapp.size();
      }
  
      @Override
      public int getColumnCount() {
          return NUM_COL;
      }
  
  
      public void removeRow(int row) {
          fireTableRowsDeleted(row, row);
      }
      
      @Override
      public Object getValueAt(int rowIdx, int columnIdx) {
          throw new UnsupportedOperationException(&quot;Not supported yet.&quot;); 
      }
      
      @Override
      public String getColumnName(int column) {
          return colNames[column];
      }
  
      @Override
      public Class&lt;?&gt; getColumnClass(int columnIdx) {
          return colTypes[columnIdx];
      }
      
  }
  </code></pre>
  </blockquote>