I have an ArrayList of Dog that looks like this,
ArrayList<Dog> array=new ArrayList<>();
array.add(new Dog("one", 10));
array.add(new Dog("two", 20));
array.add(new Dog("one", 40));
Class Dog takes a String and a Double as parameters.I'm trying to merge those ArrayList objects that have duplicate String values.At the same time i need to add their Double values. So in this example i want to get a new ArrayList that will have two Dog objects like this,
Dog ("one", 50)
Dog ("two", 20)
I've already managed to add objects with duplicate values but i'm having trouble in adding their double values.Any suggestions?
Map<String, Dog>where theStringis the dogs name. Using a list needs more work to handle the duplicates.