We're ready to discover our namesakes! We just need to write a program to realize this heartwarming goal. To start, let's create a Map, where we will add people represented by (last name, first name) pairs. Let there be ten of them, with some of them sharing last names and some of them sharing first names. After that, we'll display the contents of the Map on the screen.
Shared last names and first names
You must be signed in to leave a comment
18 April 2022, 15:04
Hint: main() don't need to print all 10 created elements. Hint²: map can't have repeated keys.
11 December 2021, 23:24
Hello everyone, special "nock nock" to the one that wrotes this/all tasks in this course, i want point/sugest some a change on missunderstood talk/requirements to all of us can complete this course sucessfuly: a) First of all , a Map is an Interface in Java plataform and it has 3 ways to implement it : 1) as a "HashMap" 2) as a "TreeMap" 3) as a LinkedHashMap. b) "Be clear" when refer to the java language sintax/terms e.g. ... createPeopleMap() method must create and return a Map with (String, String) elements. Also, add 10 people to the map ... " in here the createPeopleMap will create an 'implementation' of Map" not an interface Map wich is created in the main method to manipulet the collection alread created. it's will give us a better understand of what/how we are doing here and where we can go from there. d) about to add duplicates key in the Map, a Map can not contain duplicate keys, but here on this task you can just go ahead and type it and run the program to see the results, but in a real life as a java developer we will need to do somenthing else more to prevent this to happened in ours projects. .e.g. checking if the collection to be iterated with alredy has such key/value if so do something...
25 December 2020, 16:45
May I ask for any hint here? How to add to Map entries with the same key?
28 December 2020, 21:27
As Mojo said this task misleads us. When you add entries with same key, the old Value will be updated.
2 May 2021, 22:00
I think that's the point of this task
20 August 2020, 22:14
This taks is misleading, does the map have to contain 10 elements or do you just have to add elements 10 times. In theory doing a for loop with the same two names 10 times complies with the requierements....
Ian De Bie Full Stack Developer
21 July 2020, 23:51
add people with the same last name, although map keys are unique, hmmmm, ok, sure, genius...