If you really want to maintain a pair of ArrayLists, one containing Person objects, and the other containing the Name property of the person objects, you could always create another class:
public class PersonList {
private ArrayList<Person> people;
private ArrayList<String> names;
public PersonList() {
people = new ArrayList<>();
names = new ArrayList<>();
}
public PersonList(ArrayList<Person> p) {
people = p;
names = new ArrayList<>();
for(Person person : p) {
names.add(p.getName());
}
}
public ArrayList<Person> getPeople() {
return people;
}
public ArrayList<String> getNames() {
return names;
}
public void add(Person p) {
people.add(p);
names.add(p.getName());
}
public Person getPerson(int index) {
return people.get(index);
}
public String getName(int index) {
return names.get(index);
}
// more methods to continue to replicate the properties of ArrayList...
// just depends what you need
}
You will have to continue adding methods to this class so that this class can do everything that you can do on a single ArrayList. And really, this class is just a convenient way of making it easier to work maintain two different ArrayLists at the same time.
Anyway, now in your main code, you can instantiate an object of PersonList instead of an array list:
PersonList people = new PersonList();
And add to people. Or you could even just use a regular array list up until you need the names list, and instantiate a PersonList with the other constructor I provided:
// Assuming ArrayList<People> arrPeople exists...
PersonList people = new PersonList(arrPeople);
And now the people object will contain an ArrayList identical to arrPeople, as well as a matching names list containing all the names. And no matter how you instantiate a PersonList, calling the add method on a PersonList (same syntax as an ArrayList if you set this class up correctly), and it will keep both array lists that the class manages in sync.
(people.get(index)).getName()?