java - How to get List<Y> from Map<X,Y> by providing List<X> using google collection? -


i have map<x, y> , list<x>, extract values map<x, y> providing list<x>, result in list<y>. 1 way

list<x> keys = getkeys();   map<x, y> map = getmap();   list<y> values = lists.newarraylistwithcapacity(keys.size());   for(x x : keys){      values.add(map.get(x));   } 

now again need remove nulls in values (list<y>) using predicate or something. better way this?
there reason why method isn't there in google collections library?

something this:

list<y> values = lists.newarraylist(     iterables.filter(         lists.transform(getkeys(), functions.formap(getmap(), null),          predicates.notnull())); 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -