title: Confusing regarding .get and .set in an ArrayList
body: <p>(I'm new at Java, coming over from Python ---)</p>
  
  <p>I'm going through a tutorial and they've created a program which counts how many times a number appears in a file, then returns that number.  One particular part of the program is somewhat mysterious to me and deals with the ArrayList's .get and .set (methods? functions?).  The program goes like this:</p>
  
  <pre><code>//  (Scan a file with the numbers, say, 2 2 3 4, and put it into data1 variable.)
  //  (Make An Empty ArrayList with a bunch of 0's)
  
  Scanner data1 = null;
  ArrayList&lt;Integer&gt; count = new ArrayList&lt;Integer&gt;();
  Integer idx;
  
  while(data1.hasNextInt()){
    idx = data1.nextInt();
    System.out.println(idx);
    System.out.println(count.get(idx)+1);
    count.set(idx,count.get(idx)+1);
  }
  
  //Then prints out all the values; the ArrayList contains the number of times the number n occurs in the n-th index.
  </code></pre>
  
  <p>My question comes at the "while" part.  For concrete, let's assume data1 has the numbers 2 2 3 4.  It seems that it takes idx = 2, then puts a 1 in count[2], which is reasonable.  It then takes idx = 2 again (the next integer in data1) and puts a 2 in count[2], which is also reasonable.  <em>At this point</em>, the next number in data1 makes idx = 3, but it occurs at the index 2 in the ArrayList, so it should put a 3 in count[3], which is incorrect.</p>
  
  <p>So, what is .get and .set doing here?  Do they pop the elements off of the list when they're done with it?  Am I overlooking something?</p>