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
Post a Comment