I am working on a program where I need to take a list of objects and put them in a HashMap, using the class name as the key and the instance as the value.
I have the following code:
pets2.stream().forEach(pt -> animals.put(pt.getClass().getSimpleName(), pt));
Where pets2 is my list of animals is my HashMap. However, when I run this and then print the HashMap, only two objects from the list have been added into the Map.
Not even the first two, just two of them. Any idea as to what the issue is and how I can fix it?