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

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -