Java: True If a statement in a For loop causes the loop to break but not execute the block

This is my first post here, but I did quite a bit of research before writing. I am trying to compare strings with String.equals()

and (with the data I want) the comparison is compared to true

. I even threw in a boolean to test this. However, instead of executing the contents of the If block, it breaks out of the For loop and returns null:

public WeatherInfo getWeather (Date date, ArrayList<WeatherInfo> weather) {
    SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy");
    String eventDate = sdf.format(date);
    for (WeatherInfo w : weather) {
        Date wDate = new Date(w.getEpoch() * 1000);
        String weatherDate = sdf.format(wDate);
        if (weatherDate.equals(eventDate)) {
            return w;
        }
    }
    return null;
}

      

Anyone have any idea what might happen?

PS. Here is a screenshot of the relevant variables during True Evaluation (test is a boolean test) Variables

+3


source to share





All Articles