Search code examples
javaobjectstoremove

Temp store an object in java


Is it possible to temporarily store an object?

What I intend doing is to temporarily store an object, remove the original then put the temp object elsewhere?

So this gives the impression I'm "moving" the object effectively.

Many thanks,


Solution

  • Player tempPlayer = new Player();
    tempPlayer.setValueA() = originalPlayer.getValueA();
    // copy all values this way
    team.remove(originalPlayer);
    // more code
    team2.add(tempPlayer);
    

    Does this answer look ok?