java - Return and break in foreach-loop ArrayList -
i try execute function. private arraylist<note> notes; //adding notes in arraylist public note getnotebyday(calendar calendar) { (note note : notes) { if (note.getreminder().gettime() / constants.day_in_millis == calendar.gettimeinmillis() / constants.day_in_millis) { log.d("note_id", note.getname()); return note; } } return null; } but when call function different calendar i first note. i 2 calls of log.d() . when use break; instead return note; 1 call of log.d() where problem? 1) first note. that's because first note fulfill requirements in if statement. 2) 2 calls of log.d(). it means issue not in code in place calls method. use debugger or stacktrace determine , when calls method. multithread or multiclick - whatever environment or platform using. 3) when use break; instead return note; 1 call of