There is not a clean way to do it.
You should create a class where all the variables are stored and save an instance of that class in an ArrayList.
Actually, depending on your data, you might be able to record not a snapshot of the entire data set, but rather just what the last 5 changes made to it were. Example: Let’s say the user does the following six actions:
- Set redness from 180 to 90.
- Adjust size from 30 to 160.
- Turn up volume by 154%.
- Recombobulate the entire data set.
- Pull the latest weather info from an external site.
- Scribble a doodle over the UI.
To undo 6, you’d just need to redraw the UI without it.
To roll back 5, you’d need that full copy of the previous data. Yikes.
To undo 4, you’d need a backup of that data. Everyone knows that you can’t de-recombobulate something (it’s a one-way operation).
Those are the cases where you’d be backing things with a class, probably.
But for the first three, they are just value changes. You need not record the entire data set, just the fact that “volume”, “size”, and “redness” were what were changed, and the amounts they were previously.