Sieve of Eratosthenes to print prime numbers in a given range This is my implementation for Sieve of Eratosthenes in Java.Please let me know how can I further improve my code:

public static void main(String[] args) {

    ArrayList&lt;Integer&gt; numbers = new ArrayList&lt;Integer&gt;();

    for (int i = 2; i &lt;= 120; i++) {
        numbers.add(i);
    }

    int digit = 2;
    while (digit &lt;= numbers.size()) {
        for (int i = 0; i &lt; numbers.size(); i++) {

            if (numbers.get(i) != digit &amp;&amp; numbers.get(i) % digit == 0) {
                numbers.remove(i);
                i--;

            }

        }
        digit++;
    }

    for (int a : numbers)
        System.out.println(a);

}
This is NO Sieve of Eratosthenes. Can you see any division in this algorithm description???

What you're doing is trial division. Worsened by


even checking things like "does 100 divide 2?"
using a list which does not allow efficient removal
using Integer rather than int


The complexity is something like \$O(n^3)\$ as there are 3 nested loops: 2 in your code and 1 in numbers.remove.

The complexity should be \$O(n^\frac32)\$ which comes from using an "indicator array"(*) and iterating up to \$\sqrt n\$ only.

(*) It tracks for each int the information if it's a prime or not. It can be implemented e.g. as a boolean[] or a BitSet. The point is that all you need is an indexed access, no search, no elements shifting....