Q:

in java we can use list.remove(int index) to remove the items in that index, what if the list is huge and we can only use long to store the index?

When I use "Sieve of Eratosthenes" to generate prime number I encountered this problem. I want to create a method which takes in an list and then remove every 3rd list after 3: [2, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29...] -> [2, 3, 5, 7, 11, 13, 17, 19, 23, 25, 29...].And here is my code:
  private static void removeThird(List<Long> l) {

    int i = 1;
    int count = 0;
    while (i < l.size()) {

      // System.out.print(count + ":"); //debug
      // System.out.print(l.get(i) + " ");
      if (count == 3) {
        l.remove(i);
        count = 1;
      }
      i ++;
      count ++;
    }
  }

This code works, but because I want to generate huge amount of prime numbers so I need a very long size list. Therefore if I want to be able to access and modify each item in the list I will need a long type to store my index. So I changed int i = 0 into long i = 0, and the code doesn't work. And I viewed the docs about list class and realized that I can only call list.remove(int index). I wonder what if I want to call list.remove(long index)? Is there a way to do so? Thanks!

A:

List and its implementations are only usable for lists whose size fits in the positive half of an int. E.g., "only" up to 4,294,967,296 entries (indexes 0 - 4294967295, inclusive).
If you need to have a list that's longer than that, you'll need to find a non-JDK list type or implement your own.

