title: Java error when converting String in ArrayList to int
body: <p>I am <em>very</em> new at Java.  I am trying to write a lottery simulator.  I have the following code:</p>
  
  <pre><code>Scanner input = new Scanner(System.in);
  System.out.println("Enter six whole numbers between 1 and 49 in a comma-separated list: ");
  String userNumbersString = input.nextLine();
  String[] userNumbersArray = userNumbersString.replaceAll("\\s+","").split(",");
  ArrayList userNumbers = new ArrayList(Arrays.asList(userNumbersArray));
  boolean validNumbers = true;
  for(int v = 0; v &lt;= 6; v++){
      if((int)userNumbers.get(v) &gt; 49){
          validNumbers = false;
              v = 7;
          }else{
              v++;
          }
      }
  if(validNumbers == false){
      String[] str = new String[0];
      main(str);
  }
  </code></pre>
  
  <p>It compiles properly.  However, when I input a series of numbers, I get this error:</p>
  
  <p>java.lang.ClassCastException:
  java.lang.String cannot be cast to java.lang.Integer.</p>
  
  <p>I am very confused about why this string can't be cast to an integer.</p>
  
  <p>Sorry if this is a long-winded question, but I would hugely appreciate any help.</p>
  
  <p>I have just realised that the OutOfBounds exception was due to a stupid maths mistake on my part; v was starting at 0; there were five values in the array, but I gave the for loop the condition &lt;= 6.  Sorry about that.</p>
  
  <p>Thank you everybody for all your help.  Together, you have resolved my question.</p>