Just a minor problem with Arraylist
. I want to sort a ArrayList<Client>
by name.
Class Client{ String name; int phonenumber ..}
This code does the work, but i'm having a compiler warning: "uses unchecked or unsafe operations". Whats the problem?
public void sortByName(){
Collections.sort(ListofClients, new NameComparator());
}
My comparator looks like this:
public class NameComparator implements Comparator{
public int compare(Object client1, Object client) {
String name1 = ((Client) client1).getName();
String name2 = ((Client) client2).getName();
return name1.toUpperCase()).compareTo(name2.toUpperCase();
}
}
If i use "implements Comparator<Client>
" i get a error: "NameComparator is not a abstract and does not override abstract method compare(Client, Client) in java.util.Comparator. Is my comparator wrong? sorry for this noob question, new to java