title: How to get the actual integer value from an array list
body: <p>I am using an ArrayList of ArrayLists for a data structure to play a game of towers of hanoi.  The game is constructed and initialized as follows:</p>
  
  <pre><code>private ArrayList&lt;ArrayList&gt; lists = new ArrayList&lt;ArrayList&gt;();
  private ArrayList&lt;Integer&gt; peg1 = new ArrayList&lt;Integer&gt;();
  private ArrayList&lt;Integer&gt; peg2 = new ArrayList&lt;Integer&gt;();
  private ArrayList&lt;Integer&gt; peg3 = new ArrayList&lt;Integer&gt;();
  
  
  //Constructor
  public TowersOfHanoi() {
  
     lists.add(null);
     lists.add(peg1);
     lists.add(peg2);
     lists.add(peg3);
  }
  
  public ArrayList initializeGame(int n) {
  
      for (int i = 0; i &lt; n; i++) {
          peg1.add(i+1);
      }
  
          return peg1;
      }
  }
  </code></pre>
  
  <p>I am trying to use a Boolean method to do a check and make sure the user doesn't try to move a larger disc on top of a smaller disc, however, I don't understand how I would grab the the integer value stored in the arrayList.  The integer values should serve as a way to gauge the diameter of the discs.  I.E. 1 is smaller than two is smaller than 3 etc.  This is the code I have come up with...  I believe I am just getting the indexes and not the actual values of the integers stored there.  How can I get the actual values?</p>
  
  <pre><code>public boolean isMoveLegal(int moveFrom, int moveTo){
  
    ArrayList&lt;Integer&gt; fromPeg = lists.get(moveFrom);
    int x = (fromPeg.remove(0)).intValue();
  
    ArrayList&lt;Integer&gt; toPeg = lists.get(moveTo);
    int y = (toPeg.get(0)).compareTo(x);
  
    if(x&lt;y){
  
       System.out.println("illegal move");
    }
  
    return false;
  }
  </code></pre>