I have a small program that reads a json file that gives the weather, time, temp, wind, ect. I need to calculate the average tempature for 2009 through 2015. The years are in an array, and are in length, around 60k. I am trying to write a small loop that will first find the position of the first instance of the year 2009 and then the last instance of the year 2009. Then I can run my average temp loop through that, but I am running into an issue as seen below.
place
will be the index of the array. However, no matter how I run my
code, it always equals -1, rather than giving me the position of
the index in the array. Both arguments in the if
statements are
strings.
So what am I doing wrong?
String twozerozeronine = "2009";
int place = -1;
for (int a = 0; a < years.size(); a++){
if (years.get(a) == twozerozeronine){
place = 1;
break;
}
}
System.out.println(place);