As you said, and in the same way as you wrote the code, you will create a class that implements the Comparator interface for Ticket. First, you compare ticket names using String Comparator, and if this results in 0 (equal name), then you compare by id in the same comparator.
Make sure that the string comparator performs trimming before (delete before and after empty spaces) and, possibly, ignore the casing, which is up to you.
If you want some kind of generalization, you can write a comparator-decorator that names more specific ones. If you want to know more about this, let me know.
Luciano
source share