5. ArrayList Access Java


#1



https://www.codecademy.com/en/courses/learn-java/lessons/data-structures/exercises/arraylist-access?action=resume

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<Integer> weeklyTemperatures = new ArrayList<Integer>();
    weeklyTemperatures.add(78);
    weeklyTemperatures.add(67);
    weeklyTemperatures.add(89);
    weeklyTemperatures.add(94);
 
 System.out.println(weeklyTemperature.get(0) );


	}
}


#2

remove this line

int ArrayList = weeklyTemperatures;

and

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


#3

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


#4

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.


#5

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


#6

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


#7

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


#8

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:
http://www.javatpoint.com/ArrayList-in-collection-framework

for the constructor


#9

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