I have a Hashmap in Java like this:
private Map<String, Integer> team1 = new HashMap<String, Integer>();
Then I fill it like this:
team1.put("United", 5);
How can I get the keys? Something like: team1.getKey() to return “United”.
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.
A
HashMapcontains more than one key. You can usekeySet()to get the set of all keys.will store
1with key"foo"and2with key"bar". To iterate over all the keys:will print
"foo"and"bar".