My first assumption was the "\n" on the last number. Also I swapped list with a pure array and so one to simplify the code.
It looks like it throws an Error somewhere cuz catch(Throwable e) leads to wrong answer, but I have no clue where it might to be.
import java.util.Arrays;
public class Main {
public static int[] byteArray(int cap) {
boolean[] is_composite = new boolean[cap - 2 >> 1];
int[] result = new int[(int) Math.ceil(1.25 * cap / Math.log(cap))];
int pos = 1;
result[0] = 2;
for (int i = 0; i < cap - 2 >> 1; ++i) {
if (!is_composite[i]) {
result[pos++] = (i * 2 + 3);
for (long j = 4L * i * i + 12L * i + 9; j < 2 * is_composite.length + 3; j += 4 * i + 6) {
is_composite[(int) (j - 3L >> 1)] = true;
}
}
}
if (result.length > pos) {
result = Arrays.copyOf(result, pos);
}
return result;
}
public static void main(String[] args) {
int[] arr = byteArray((int) Math.pow(10, 8));
for (int i = 0; i < arr.length; i += 100) {
if (i + 100 < arr.length)
System.out.println(arr[i]);
else
System.out.print(arr[i]);
}
}
}