Teste mal, ob es mit Lambdas gegenüber normalen Arrays schneller ist:
[code=Java] public static void main(String[] args) {
long t1 = System.currentTimeMillis();
int[] array = sieb(100000000);
long t2 = System.currentTimeMillis();
System.out.println(array[array.length - 1]);
System.out.println(t2 - t1);
}
private static int[] sieb(int end) {
int[] array = IntStream.range(0, end).map(o -> o % 2 == 0 ? 0 : o).toArray();
for (int i = 3; i < array.length; i += 2) {
if (array[i] != 0) {
for (int j = i * 2; j < array.length; j += i) {
array[j] = 0;
}
}
}
return Arrays.stream(array).filter(o -> o != 0).toArray();
}[/code]
Endlich mal ist der Speicher das Problem dabei. 