You really need to override toString () in your Person class, which will return the first name, because the ArrayList automatically calls the toString of the enclosing types to print the string representation of the elements.
@Override public String toString() { return this.firstname; }
So, add the above method to your Person class, and you will probably get what you want.
PS : - On a side note, you do not need to do people.toString() . Just execute System.out.println(people) , it will automatically call the toString() method for ArrayList .
source share