This error keeps occurring Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 131071
I'm trying to create an array of 131071 integers with no duplicates.
public class array {
public static void main(String[] args) {
populateArray();
}
public static void populateArray(){
int [] numbers = new int [131071];
int k = 0;
Random r = new Random();
for (int i = 0; i < 131070 ; i++) {
int random=r.nextInt(13071)+1;
for (int h = 0; h <= i; h++) {
if (random != numbers[h]) {
numbers [k] = random;
k=k+1;
}
}
}
for (int j = 0; j < 131071; j++) {
Arrays.sort(numbers);
System.out.println(numbers[j]);
}
}
}