public int compare(Person firstPerson, Person secondPerson) { String personName1 = firstPerson.getFirstName().toUpperCase(); String personName2 = secondPerson.getFirstName().toUpperCase(); // ascending order return personName1.compareTo(personName2); // descending order // return fruitName2.compareTo(fruitName1); }
public static void displayList(Person[] persons) { for (int i = 0; i < 4; i++) { Person person = persons[i]; String lastName = person.getLastName(); String firstName = person.getFirstName(); int age = person.getAge(); System.out.println(lastName + ", " + firstName + ". Age:" + age); } System.out.println(); }