java - How to get Map.values as a Set rather than a Collection? -


i have map map<string, sometype> every instance of sometype added name map.put(object.getname(), object). in end, there no duplicates in map.values().

now, want set<sometype> map without making copy new hashset<>(map.values()).

is possible, preferential standard library?

you know how new hashset<>(map.values()). can't set of values directly, since values can contain duplicates. if in specific map there no duplicate values, in general map there can duplicate values.

you can java 8 streams, has no advantage on instantiating set explicitly.

set<sometype> values = map.values().stream().collect(collectors.toset()); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -