C
Colin Hemmings
Hi there, I was wondering if anybody could possibly help me with my
problem. I have an ArrayList of objects declared as:
ArrayList playerList = new ArrayList();
I have filled the ArrayList with several player objects. My player
objects have a method called 'updateName()', which changes that players
name with the name it is passed.
Currently to change the name of a player in the ArrayList I have to do
the following:
Player tempPlayer = new Player();
tempPlayer = (Player) playerList.get(X);
tempPlayer.updateName("Phillip");
This code works fine, but I was wondering if there is a way of
manipulating the object just using its reference, without having to
retrieve the entire object. For instance, something similar to the
following:
playerList[X].updateName("Phillip");
Similar to the way you access elements in a standard array?
Or is there a better way of accessing elements than what I am doing in
the first example?
Thanks Kindly for any help
problem. I have an ArrayList of objects declared as:
ArrayList playerList = new ArrayList();
I have filled the ArrayList with several player objects. My player
objects have a method called 'updateName()', which changes that players
name with the name it is passed.
Currently to change the name of a player in the ArrayList I have to do
the following:
Player tempPlayer = new Player();
tempPlayer = (Player) playerList.get(X);
tempPlayer.updateName("Phillip");
This code works fine, but I was wondering if there is a way of
manipulating the object just using its reference, without having to
retrieve the entire object. For instance, something similar to the
following:
playerList[X].updateName("Phillip");
Similar to the way you access elements in a standard array?
Or is there a better way of accessing elements than what I am doing in
the first example?
Thanks Kindly for any help