бесплатные читы для вормикс вконтакте в контакте взлом вормикса скачать программу для вормикс вконтакте вормикс баги деньги wpe pro вормикс скачать качалка на вормикс скачать программу на игру вормикс скачать программу для взлома вормикса вконтакте вормикс скачать читы скачать программу вормикс контакте баги вормикс на фузы коды на вормикс бесплатно без смс взлом вормикс artmoney баг вормикс бесплатно коды на вормикс в контакте прокачка вормикс взлом программа скачать читы для вормикс на рубины вормикс баги на оружие прокачка вормикс в контакте без смс бесплатно баг вормикс cheat engine взлом игры вормикс вконтакте коды на вормикс в контакте на 30 уровень программа для накрутки рубинов в вормиксе вормикс баги на рубины баг вормикс вконтакте рубины коды на вормикс читы на вормикс на деньги прокачка игры вормикс вормикс программа для взлома cheat engine пользоваться вормикс вормикс мастер скачать бесплатно вормикс прокачка героя читы вормикс фузы вормикс боссы с какого уровня коды на вормикс для 10 уровня

How to remove all null elements from a Collection?

Posted by Mike Haller on Sunday, February 4. 2007 at 00:24 in Java
A slightly annoying discussion was going on tonight on a Java IRC channel. It was all about how to remove null elements from an ArrayList.

There have been a lot of questions by various people. Besided suggestions, technical questions, there have also been the
usual suspects like "Why on earth are you adding null elements anyway?".

But let's have a look at the result, which seems to be the easiest way:

list.removeAll(Collections.singleton(null));


If you don't know the Collections class, you might have been come up with something like this:

list.removeAll(Arrays.asList(new Object[]{null}));


Is there any other way to remove null references from collections? For example by using HashSets and only use remove(null). Or is it better to implement your own implementation of a Collection which does it itself?
What are the performance benefits of each variation? Could we use the Java High Performance Collections implementation Trove?


Add Comment

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications
 
Submitted comments will be subject to moderation before being displayed.
 

About

My name is Mike Haller and I'm a software developer and architect at Bosch Software Innovations in Germany. I love programming, playing games and reading books. I like good food, making photos and learning and mentoring about the craftsmanship of commercial software development. Stack Overflow profile for mhaller

Quicksearch

Archives