There are two ways to handle this scenario. We can use these
options:
Comparable: Implement the Comparable interface for Customer
class and compare customer objects by firstName attribute.
Comparator: Implement Comparator for comparing two Customer
objects on the basis of firstName attribute. Then use this comparator
object in sort method of Collections class.
https://www.geeksforgeeks.org/how-to-sort-an-arraylist-of-objects-by-property-in-java/