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
Post a Comment