Ten cats

  • 6
  • Locked
I'd like ten cats and Java expertise, please. Preferably at the same time! Not a problem, hang on: the program has a Cat class with a String variable name. You need to create a Map and add 10 cats represented by (name, Cat) pairs. Then get a Set of all cats from the Map and display it on the screen.
You can't complete this task, because you're not signed in.
Comments (6)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Level 10 , Dresden, Germany
2 December 2021, 20:36
Do only convert the values of the map into a set and then return them as the items of the set. You need not convert the map keys. The requirement "return the set of cats retrieved from the passed map" is misleading. The following article helped me:
Level 15 , Old Town, United States
12 May 2021, 22:08
solved it with for-each lamda expression(learned from googlin), but actually there was even simpler way to do it, which was to pass in the map.values() as the HashSet<Cat> parameter. Good learning experience. Happy coding! :)
Roman Grygorczuk
Level 19 , Cracow, Poland
17 October 2020, 22:29
Well I had stuck with convertMapToSet. Can you recommend any article? I use sourceMap.values() but get me only one value.
Roman Grygorczuk
Level 19 , Cracow, Poland
17 October 2020, 22:40
Ok, I did it. But I don't understand why it worked now but didn't previously. Can someone explain?
Roman Grygorczuk
Level 19 , Cracow, Poland
17 October 2020, 22:46
Ok, now I know. Values returns a Collection view which represents a group of objects. And I had only one reference variable (means object) for values under each unique key. So it copied only that one reference variable.
Level 29 , Seattle, United States
24 January 2019, 18:10
"I'd like a dozen cats..." 10 is not a dozen.