Data Structures #5 ArrayList: Access Bug


#1

So I ran into a bug. Basically it says that the quizeGrades.add(95); is in the position 0 in the ArrayList. So I did what anyone else would do and follow what it says so I grabbed weeklyTemperatures.add(78); using System.out.println( weeklyTemperatures.get(0) ); because it's in position 0 in the ArrayList right?

When I clicked run it didn't work. I got the popup asking me if I wanted to get the code and I did it because I knew nothing was wrong with what I put in. I followed exactly what the direction had said. According to the correct answer, weeklyTemperatures.add(78); is in position 1 in the ArrayList and I had to put a 1 instead of a 0 in System.out.println( weeklyTemperatures.get(1) );

So which one is it? Is weeklyTemperatures.add(78); on position 0 or position 1 on the ArrayList?


#2

Hi @sp3nc3rxd ,

If you are on Exercise 5: ArrayList: Access, and have this immediately after you create the ArrayList ...

weeklyTemperatures.add(78);
weeklyTemperatures.add(67);

... then, 78 is at index 0 of weeklyTemperatures. But, the value 67, which is the lowest temperature there, is at index 1.


#3

But he get in result 78 !
He should get result -----> 67 because is written ------> get(1)
Bug !


#4

not a bug, what is being asked is to provide the correct get --> option
so that the lowest temperature will be printed in the output. It appears that
it is asking what number is in get(0) and have that printed according to the question and example, but actually you are correct, the get(1) is the weeklyTemperatures in that is the lowest!


#5

Hi Guys!

So this is my code:

import java.util.ArrayList;

public class Temperatures {

public static void main(String[] args) {

ArrayList weeklyTemperatures = new ArrayList();
weeklyTemperatures.add(78);
weeklyTemperatures.add(67);
weeklyTemperatures.add(89);
weeklyTemperatures.add(94);

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

Is it not giving error, but it is not letting me continue and I cannot find what is it that I am doing wrong.


#6

This is crazy, I've just copied the text from the exercise, replaced the values and it worked. Honestly I cannot find the difference:

import java.util.ArrayList;

public class Temperatures {

public static void main(String[] args) {

ArrayList weeklyTemperatures = new ArrayList();
weeklyTemperatures.add(78);
weeklyTemperatures.add(67);
weeklyTemperatures.add(89);
weeklyTemperatures.add(94);

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