title: print() method not printing correct ArrayList contents
body: <p>My code converts decimal to binary like so:</p>
  
  <pre><code>for(int i = 0; i &lt; combinations; i++)
      {
          int binary[] = new int[numV];
          if(i == 0)
          {
              for(int j = 0; j &lt; numV; j++)
              {
                  binary[j] = 0;
              }
          }
          else if(i &gt; 0)
          {
              binary = values.get(i-1);
              for(int a = numV-1; a &gt;= 0; a--)
              {
                  System.out.println(a);
                  if(binary[a]==0)
                  {
                      binary[a]++;
                      break;
                  }
                  else
                      binary[a]=0;
              }
          }
          values.add(binary);
      }
  </code></pre>
  
  <p>As you can see, the <code>values</code> object of type <code>ArrayList&lt;int[]&gt;</code> stores the binary value of <code>i</code> (from the instanced integer array <code>binary</code> that gets created with each loop of <em>i</em>). However immediately after printing all the integer array representation of the binary number for each <code>i</code>, from the list, it gives the following output:</p>
  
  <pre><code>0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  0000
  </code></pre>
  
  <p>My <code>print()</code> part of the code works fine. The contents in the ArrayList are incorrect and I don't know why. Can someone point out my silly mistake? Thanks.</p>
  
  <p>EDIT : When I print, it prints the LAST arraylist's integer array only (when i print after the for loop). However when I print what has been just added to the array list within the for loop, its contents are correct.</p>
  
  <p>COMPLETE CODE:</p>
  
  <pre><code>    import java.awt.BorderLayout;
  import java.awt.Font;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.ArrayList;
  
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  
  public class KMap extends JFrame
  {
      private ArrayList&lt;String&gt; variableNameList = new ArrayList&lt;String&gt;();
      private String [] characters = {"A","B","C","D","E","F","G","H","I","J"};
  private ArrayList&lt;int[]&gt; values = new ArrayList&lt;int[]&gt;();
  public KMap() 
  {
      setTitle("Karnaugh Map for COMP 228");
      setLayout(new BorderLayout());
      createTopPane();
      updateVarialbes(4);
      pack();
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
      setLocationRelativeTo(null);
  }
  public void createTopPane()
  {
      JPanel topPanel = new JPanel();
      topPanel.setLayout(new GridLayout(1,10));
      JLabel numVariablesString = new JLabel();
      numVariablesString.setText("# Variables =&gt; ");
      topPanel.add(numVariablesString);
      JButton[] variableButton = new JButton[9];
      for(int i = 0; i &lt; variableButton.length; i++)
      {
          int numV = i+2;
          variableButton[i] = new JButton();
          variableButton[i].setText(Integer.toString(numV));
          variableButton[i].addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e) 
              {
                  removeLeftPane();
                  removeRightPane();
                  updateVarialbes(numV);
              }
          });
  
          topPanel.add(variableButton[i]);
      }
      add(topPanel, BorderLayout.NORTH);
  }
  public void updateVarialbes(int numV)
  {
      int combinations = (int) Math.pow(2,numV) + 1;
      System.out.println(combinations);
      System.out.println("New variables: " + numV);
      values.clear();
      variableNameList.clear();
      for(int i = 0; i &lt; numV; i++)
          variableNameList.add(characters[i]);
      System.out.println();
      for(int i = 0; i &lt; combinations; i++)
      {
          int binary[] = new int[numV];
          if(i == 0)
          {
              for(int j = 0; j &lt; numV; j++)
              {
                  binary[j] = 0;
              }
          }
          else if(i &gt; 0)
          {
              binary = values.get(i-1);
              for(int a = numV-1; a &gt;= 0; a--)
              {
                  System.out.println(a);
                  if(binary[a]==0)
                  {
                      binary[a]++;
                      break;
                  }
                  else
                      binary[a]=0;
              }
          }
          values.add(binary);
      }
  
      for(int i = 0; i &lt; values.size(); i++)
      {
          for(int j = 0; j &lt; values.get(i).length; j++)
              System.out.print(values.get(i)[j]);
          System.out.println();
      }
  
  
  
      createLeftPane(numV);
      createRightPane(numV);
  }
  public void createLeftPane(int numV)//numV = number of variables to display
  {
      JPanel leftPanel = new JPanel();
      leftPanel.setLayout(new GridLayout(2,2));
  
  
  
      JLabel variableLabel[] = new JLabel[numV];
      JPanel topLeftInnerPanel = new JPanel();
      topLeftInnerPanel.setLayout(new GridLayout(1,numV));
      for(int i = 0; i &lt; numV; i++)
      {
          variableLabel[i] = new JLabel();
  
          variableLabel[i].setText(variableNameList.get(i));
          topLeftInnerPanel.add(variableLabel[i]);
      }
      leftPanel.add(topLeftInnerPanel);
  
  
  
      JPanel topRightInnerPanel = new JPanel();
      JLabel functionLabel = new JLabel();
      String s = "F(";
      for(int i = 0; i &lt; numV; i++)
      {
          s+=characters[i];
          if(i!=numV-1)
              s+=",";
      }
      s+=(")");
      System.out.println(s);
      functionLabel.setText(s);
      topRightInnerPanel.add(functionLabel);
      leftPanel.add(topRightInnerPanel);
  
  
  
  
      JPanel innerLeftPanel = new JPanel();
      innerLeftPanel.setLayout(new GridLayout(values.size(), 1));
      JPanel[] innerLeftValuesPanel = new JPanel[values.size()];
      for(int i = 0; i &lt; values.size(); i++)
      {
          innerLeftValuesPanel[i] = new JPanel();
          innerLeftValuesPanel[i].setLayout(new GridLayout(1, numV));
          for(int j = 0; j &lt; values.get(i).length; j++)
          {
              JLabel l = new JLabel();
              l.setText(Integer.toString(values.get(i)[j]));
              innerLeftValuesPanel[i].add(l);
          }
      }
  
      for(int i = 0; i &lt; (2^numV); i++)
          innerLeftPanel.add(innerLeftValuesPanel[i]);
      leftPanel.add(innerLeftPanel);
  
  
      JPanel innerRightPanel = new JPanel();
      innerRightPanel.setLayout(new GridLayout(2^numV, 1));
  
      add(leftPanel);
  
  }
  public void removeLeftPane()
  {
  
  }
  public void createRightPane(int numV)
  {
  
  }
  public void removeRightPane()
  {
  
  }
  </code></pre>
  
  <p>}</p>