title: Using a long as ArrayList index in java
body: <p>I am writing this java program to find all the prime numbers up to num using the Sieve of Eratosthenes, but when I try to compile, it says I can't use a long var as an array index, and it expects an int var in its place. But I'll be working with large numbers, so I can't use int. What can I do?</p>
  
  <pre><code>import java.util.*;
  import java.lang.*;
  
  public class t3{
      public static void main(String[] args){
          long num = 100;
  
          //declaring list and filling it with numbers
          ArrayList&lt;Long&gt; numlist = new ArrayList&lt;Long&gt;();
          for(long x=2 ; x&lt;num ; x++){
              numlist.add(new Long(x));
          }
  
          //sieve or eratosthenes
          for(long x=0 ; x&lt;Math.sqrt(num) ; x++){
              for(long y=x+1 ; y&lt;numlist.size() ; y++){
                  if(numlist[y]%numlist[x] == 0){
                      numlist.remove(y);
                  }
              }
          }
  
          //print list
          for(Object item : numlist){
              System.out.println((Long)item);
          }
      }
  }
  </code></pre>