mercredi 22 mars 2017

JAVA trying to find positions of the year. Not Working

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

Aucun commentaire:

Enregistrer un commentaire