java - Convert Map to ArrayList where entry value = something -


i using map<user, integer> , need select users specific integers , add them arraylist, easiest way users arraylist<user> integer = 1?

this tried, works, appreciate shorter code.

arraylist<user> users = new arraylist();  (map.entry<user, integer> entry : useranswers.entryset()) {     if(entry.getvalue()==1) users.add(entry.getkey()); } 

edit: thank danil gaponov, answer looking for!

requires java 8:

map.entryset().stream()     .filter(e -> e.getvalue().equals(1))     .map(e -> e.getkey())     .collect(collectors.tolist()); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -