Did you use the `add` method to add `111` at index `2`?


#1

Output is perfect but still i get error. what would be the reason


#2

@nikhilsharma_y
Can you give us the link to your exercise and print your code?


#3

even i am getting the same error


#4

my code:

import java.util.ArrayList;

public class Temperatures {

public static void main(String[] args) {
ArrayList<Integer> weeklyTemperatures= new ArrayList<Integer>();
weeklyTemperatures.add(78);
weeklyTemperatures.add(67);
weeklyTemperatures.add(89);
weeklyTemperatures.add(94);
weeklyTemperatures.add(2,111);

System.out.println( weeklyTemperatures.get(3) );
}
}