I am trying to sort an array by name ( that works) but I only need each sorted name to show up once, regardless of how many times it shows up in the sort. Where do I go from here?
Code:
public class Report {
Rental[] rentals = new Rental[20];
/** Creates a new instance of Report */
public CustomerReport() {
}
public Rental[]sort(Rental[] rentals)
{
Rental[] newRentals = new Rental[rentals.length];
for (int i = 0; i < rentals.length; i++){
newRentals[i] = rentals[i];
}
int n = rentals.length;
for (int pass=1; pass < n; pass++){
for(int i=0; i< n-pass; i++){
int result = newRentals[i].getCustomer().getName().compareTo(newRentals[i+1].getCustomer().getName());
if(result > 0)
{
Rental temp = newRentals[i];
newRentals[i] = newRentals[i+1];
newRentals[i + 1] = temp;
}
}
} return newRentals;
}
public Rental[] getRentals(){
return rentals;
}
}
Comment