Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing null values from a Guava SetMultimap?

Tags:

java

guava

If I have a SetMultimap like the following:

SetMultimap<String, MyObject> map = HashMultimap.create();
map.put("a", new MyObject());
map.put("a", null);
map.put("b", null);

What is the best way to remove the null values from this collection, so that I end up with something like (i.e. some keys will have only null values, but I still want the key):

   a -> obj
   b -> empty
like image 290
user2586917 Avatar asked May 12 '26 00:05

user2586917


1 Answers

Multimap<String, String> filteredMap = Multimaps.filterValues(map, Predicates.notNull());
like image 152
Oussama Zoghlami Avatar answered May 14 '26 13:05

Oussama Zoghlami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!