How to modify an attribute of an object in an ArrayList?

1

I created a ArrayList(objetoQueCriei) , and I would like during program execution to change the value of the attributes of those objects in the array. Do you have any commands to do this?

I tried to use the set command, but would have to replace the object of that index, not replace a value of an attribute of the object.

    
asked by anonymous 22.10.2016 / 01:50

1 answer

3

What @DenerCarvalho said is correct, I will only post here because I want to mention another observation:

listaDeObjetos.get(indice).setAtributoQualquer("Valor Novo");

As listaDeObjetos holds only the reference of the object, you can pass the refence to another object and manipulate, it will be simpler, for example:

MeuObjeto temp = listaDeObjetos.get(indice);
temp.setAtributoQualquer("Valor Novo");

I hope I have helped !!

    
22.10.2016 / 02:09