I need to know how to replace an object that is in an ArrayList<Animal> .
I have a list of arrays named ArrayList<Animal> . This list contains only 5 animals listed.
Animal animal = new Animal(); animal.setName("Lion"); animal.setId(1); ArrayList<Animal> a = new ArrayList<Animal>(); a.put(animal);
Later I will take an object from this list of arrays and modify it.
Animal modifiedAnimal = new Animal(); animal.setName("Brown Lion"); animal.setId(1);
Now I need to add this Animal object to the list of the ArrayList<Animal> a array. I need to replace the previous Animal object, which we named it Lion . How can i do this?
Note. I do not know the index to which this object is added.
user1315906
source share