6. ArrayList: Insertion

I got it to print 89 like it wants but I don’t know whats wrong

Hi remenber that you add 111 to the index 2 so the index of the 89 changed.

I did that as you can see from the picture. It printed out 89 but it said it was wrong. I did the “get code” and it look the exact same

weeklyTemperatures.add(2, 111);
System.out.println ( weeklyTemperatures.get(3) );

Hi try to refresh the page.

import java.util.ArrayList;

public class TemperaturesB {

public static void main(String[] args) {

	ArrayList<Integer> weeklyTemperatures = new ArrayList<Integer>();

weeklyTemperatures.add(2, 111);
System.out.println( weeklyTemperatures.get(3) );




I have a question about this section:
What is the benefit of adding to the list by (2, 111)???
wouldn’t it be easier to just add in the extra line of code in the ArrayList??


Какое то не очень полностью оговоренное задание. Сказано получить 89, но не сказанно что нужно удалить предыдущий вызов 111. Не хорошо так делать!


In the previous topic of OOP, I had few such issues where I wrote it perfectly and the output was correct but still it was showing the error. In fact, I copied my written codes and then replace with the codecademy’s help code and it was the same. There is some random issue with the website. I tried to refresh/ reopen it but I was not abe to go to the next level. Only option was to use the help code and move forward.

hello! can you help me please?

my code is:
weeklyTemperatures.add(2, 111);
System.out.println( weeklyTemperatures.get (0) );

The result is 78

Why and how did you entered 3?

Thanks for your help in advance!

Have a nice day!

So the website is being dumb, but I found a way around this! Get rid of all the spaces in your println statement, so it looks like this:


1 Like