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
java android


source to share


No one has answered this question yet

Check out similar questions:

2248
Is a finally block always executable in Java?
1729
How to break out of nested loops in Java?
1249
How does the Java loop for each loop work?
1215
Why is Java code executed in comments with some Unicode characters?
845
'For' loop for iterating over an enum in Java
778
How do I execute a method execution in Java?
472
Calling delete in foreach loop in Java
-1
Format the date and return a date, not a string
-1
ParseException: Exception date exception
-4
How can I check if a string representing a timestamp is a valid date in Java?



All Articles
Loading...
X
Show
Funny
Dev
Pics