6. ArrayList: Insertion


#1

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


#2

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


#3

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) );


#4

Hi try to refresh the page.


#5

import java.util.ArrayList;

public class TemperaturesB {

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) );
  


}

}


#6

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??


#7

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


#8

Hi,

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.


#9

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!


#10

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:

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


#11