There is a method in the Collections class.
Set<E> Collections.newSetFromMap(<backing map>)
What does it mean by the backing map and the set backed by a map?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Perhaps it would be illuminating to look at the implementation:
Edit – added explanation:
The map that you provide is used as the
mfield in this object.When you add an element
eto the set, it adds an entrye -> trueto the map.So this class turns your
Mapinto an object that behaves like aSetby simply ignoring the values that things are mapped to, and just using the keys.