Last Updated: January 28, 2019
·
640
· quartzde

Prevent null check before collection.add

Instead of

if (o != null) {
   collection.add(o);
}

write

collection.add(o);
collection.removeAll(asList((String) null));

2 Responses
Add your response

It may depends on the situation. I still prefer the first on game dev as it'll be faster.

over 1 year ago ·

Why you don't create your own collection with this logic?

over 1 year ago ·