I’m trying to store an object person in an ArrayList.
I have an ArrayList<String> customer = new ArrayList<String>();
The object ‘person’ has two variables: name (String) and pNr (long).
I have tried to simply add it: customer.add(person) but that doesn’t seem to work.
To clarify: I don’t want to store the variables individually. I want to store the entire object person in the ArrayList.
I simply can’t figure out how to engage this problem or even if it can be done.
Can someone point me in the right direction?
Change your
Listsuch that it accepts a Person object instead of aString.