5. ArrayList Access Java

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/learn-java/lessons/data-structures/exercises/arraylist-access?action=resume

<In what way does your code behave incorrectly? Include ALL error messages.>Temperatures.java:5: error: cannot find symbol
int ArrayList = weeklyTemperatures;
^
symbol: variable weeklyTemperatures
location: class Temperatures
Temperatures.java:12: error: cannot find symbol
System.out.println(weeklyTemperature.get(0) );
^
symbol: variable weeklyTemperature
location: class Temperatures
2 errors
T

```

Replace this line with your code.
import java.util.ArrayList;

public class Temperatures {
public static void main(String args) {
int ArrayList = weeklyTemperatures;
ArrayList weeklyTemperatures = new ArrayList();
weeklyTemperatures.add(78);
weeklyTemperatures.add(67);
weeklyTemperatures.add(89);
weeklyTemperatures.add(94);

System.out.println(weeklyTemperature.get(0) );

}

}

<do not remove the three backticks above>

remove this line

int ArrayList = weeklyTemperatures;

and

remember you have to print the lowest temperature contained in weeklyTemperatures.

1 Like

wait so you just need to remove the int Arraylist = weeklyTemperatures in the correct code?

int ArrayList = weeklyTemperatures;
weeklyTemperatures is trying to refer to a variable that hasn’t been created yet,
and also int ArrayList means you’re declaring an int variable named ArrayList.
I haven’t tried something like this yet, but this could mean you’re overwriting your import java.util.ArrayList
because you import ArrayList from the util library, then you make a new declaration under the same name as an int.
so any future references of ArrayList could cuase trouble. (but i could be wrong.)

so simply removing that line will solve the problem, the rest of your code looks fine.

can you tell me where is the mistake in this code, its not executing.

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(0) );
}
}

that’ IS a valid way of doing that, but it probably wont pass Codecademy’s own testing functions.
look above to see how they are constructing their ArrayList

im stuck in this code for 3 days, please give me a solution.

I hate to give solutions to people, because it doesn’t really help you learn, or think the solution through.
What i do is I give hints, enough to try and make you think and understand the problem.

Have a look here:

for the constructor

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.