First of all the code is not sorting (rather printing ) all the names of the input customer array.
You can use the Set Interface to make sure only one String (no redundant) is stored in it. You can read the documentation here. Set Interface Since you are pretty new to Java see below modified code to use Set interface in your program.
Please let us know if you coded the Customer class that implements Comparable interface. As I think the sort can be done easily if we use collection of customer objects rather than array of customer objects.
Please see the output below from your code and can you figure out why some names are missed?
Alex - missing after code does sorting
Andrej - missing after code does sorting
Unless this is a homework assignment, you can use the Collections framework for this. java.util.Collections has two methods to sort any List. So store the elements in a List and call one of those two methods.
To filter out any duplicate elements, use a TreeSet. That has automatic sorting, and also automatic duplicate filtering.
Please don't ask the same question twice. I don't think you are going to get an answer from the OP, but I am going to close this discussion anyway to prevent duplication of effort. I have given you links where you can find answers anyway, in your other thread.
Who among you feels worthy enough to be my best friend? Test 1 is to read this tiny ad: