title: How to get the whole row of a JTable to save it into another table?
body: <p>I am trying to validate that when the column step is equal to 2 the row is copied to another <code>JTable</code>.</p>
  <p>But the <code>jtable_step2</code> I have not initialized correctly,
  that's why it returns the error:</p>
  <pre><code>jtable_step2.setValueAt(jtable.getValueAt(i, j), row, j);
  
  Exception in thread &quot;main&quot; java.lang.ArrayIndexOutOfBoundsException: 0 &gt;= 0
  </code></pre>
  <p>How do I copy the same columns and rows that satisfy the condition?</p>
  <p>Java code:</p>
  <pre><code>import javax.swing.JTable;
  
  public class TestJTableCopy {
  
      public static void main(String args[]){
          String data[][]={ {&quot;1&quot;,&quot;/LOCAL/USER/LOCAL&quot;, &quot;20220421&quot;, &quot;1&quot;},
                            {&quot;1&quot;,&quot;/LOACL/USER/LOCAL&quot;, &quot;20220421&quot;, &quot;2&quot;},
                            {&quot;1&quot;,&quot;/LOACL/USER/LOCAL&quot;, &quot;20220422&quot;, &quot;2&quot;} };
          String columns[] = {&quot;LINE&quot;, &quot;SOURCE&quot;, &quot;DATE&quot;, &quot;STEP&quot;};
          final JTable jtable = new JTable(data,columns);
          
          JTable jtable_step2 = new JTable();
          //jtable2.addColumn(columns);
          int row = 0;
          for (int i = 0; i &lt; jtable.getRowCount(); i++) {
              //STEP == 2
              if (jtable.getValueAt(i, 3).equals(&quot;2&quot;)) {
  
                  for(int j = 0; j &lt; jtable.getColumnCount(); j++) {
                      jtable_step2.setValueAt(jtable.getValueAt(i, j), row, j);
                  }
                  row++;
              }
          }
          
          for (int i = 0; i &lt; jtable_step2.getRowCount(); i++) {
              for (int j = 0; j &lt; jtable_step2.getColumnCount(); j++) {
                  System.out.println(i + &quot; &quot; + j + &quot; &quot; + jtable_step2.getValueAt(i, j));
              }
          }
     }
  }
  </code></pre>