public static void main(String[] args) {
List<Integer> values = new ArrayList<>(30);
for (int i = 0; i < values.size(); i++){
values.add(i, 0);
}
int j = 0;
int ghh = values.get(j);
}
Above is a simple code snippet that gives an OutOfBoundException
at the last line. Why is this exception being thrown? Do I actually need to use the for-loop for initiating 0
value of all the elements of the list?