package com.codegym.task.task08.task0821;
import java.util.HashMap;
import java.util.Map;
/*
Shared last names and first names
*/
public class Solution {
public static Map<String, String> createPeopleList() {
Map<String, String> people = new HashMap<String, String>() {{
put("Aaa", "Brian");
put("Bbb", "Casey");
put("Ccc", "Eliot");
put("Ddd", "Justin");
put("Eee", "Mitch");
put("Fff", "Tyler");
put("Ggg", "Tom");
put("Hhh", "Nick");
put("Jjj", "Tyler");
put("Aaa", "Lucas");
}};
return people;
}
public static void printPeopleList(Map<String, String> map) {
for (Map.Entry<String, String> s : map.entrySet()) {
System.out.println(s.getKey() + " " + s.getValue());
}
}
public static void main(String[] args) {
Map<String, String> map = createPeopleList();
printPeopleList(map);
}
}
I don't have idea
Under discussion
Comments (1)
- Popular
- New
- Old
You must be signed in to leave a comment
Gellert Varga
16 July 2020, 20:05
1.) The requirements talk about "createPeopleMap() method".
But where is this in your program? I can't see it.
2.) Have you tried the program?
Have you counted how many item-pairs there are in the output?
(Do it!)
We learned this: All the keys of the HashMap should be unique.
If you try to put two or more equal keys, then the new one will overwrite the previous one.
0