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

  1. i first note.
  2. i 2 calls of log.d().
  3. 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 log.d() problem?

that confirms case 2. on break returns null , calling place has null pointer exception , not call again.

bottom line - issue not in provided code in place method called. eclipse has nice feature - shows method used - use feature.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -