java - Default nullpointexception checker for a for each loop -


is there default nullpointerexception checker for each loop?

for example, right writing each loop can loop list. in order test list not null, must test explicitly.

can code simplified default nullpointerexception checker not aware of? way dont have create if statement , check null manually.

my current code:

if (mylist != null) {      (string item : mylist) {           ...;           ...;      } } 

one approach use java 8 stream api filter out nulls:

mylist.stream()    .filter(objects::nonnull)    .foreach(elem -> dosomething(elem)); 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -