Error java.lang.IndexOutOfBoundsException: Index: 1000, Size: 1000
937555May 22 2012 — edited May 23 2012This is my below code in which I am trying to generate random unique number between 0 and 1001 and pass that number to some method. But this code gives me index out of bound exception. I am not sure why it is giving me that exception. Can anyone suggest me why is it happening?
public class Testing4 {
private static List<Integer> randomNumber;
private static int endRange = 1000;
public static void main(String args[]) throws IOException {
randomNumber = new ArrayList<Integer>();
for (int i = 1; i<= endRange; i++) {
randomNumber.add(i);
}
System.out.println(randomNumber.size());
Collections.shuffle(randomNumber);
try {
for (int i = 1; i<= endRange; i++) {
// Pass the unique random number between 0 and 1000 to this method
randomNumberMethod(randomNumber.get(i));
}
} catch(Exception e) {
System.out.println("Error " +e);
}
}
private static void randomNumberMethod(Integer integer) {
// TODO Auto-generated method stub
System.out.println("Number " +integer);
}
}
Edited by: user10204577 on May 22, 2012 12:15 PM