Given a map such as:
Map<String, Integer> = new Hashmap<String, Integer>;
How can I get a Collection<Integer> (any implementation of Collection would do) of the entrySet? Doing .entrySet() doesn’t seem to work.
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.
If you want to get just the map values you can use the
values()method. The Javadoc page is here.This is because your requirement is a Collection of Integers and the map values are of Integer type.
entrySetreturns a collection ofMap.Entry, each instance of which contains both the key and value that make up the entry, so if you want both the key and value, useentrySet()like soSet<Map.Entry<String, Integer>> entries = map.entrySet()