Hi need Help regarding java collection sorting. It gives me this error:
Bound mismatch: The generic method sort(List) of type Collections is not app
You can't sort a List of objects that don't implement the Comparable
interface. Or rather, you can, but you have to provide a Comparator
to the Collections.sort()
method.
Think about it: how would Collections.sort()
sort your list without knowing when a WifiSSID is smaller or bigger than another one?
You want to use Collections.sort(wifiList, new SortSSIDByid());
EDIT:
You defined your own proprietary Comparator
interface, and implement this proprietary Comparator interface in SortSSIDByid
. Collections.sort()
wants an intance of java.util.Comparator
. Not an instance of your proprietary Comparator interface, that it doesn't know.
Just add this import import java.util.Comparator;
and remove this interface
interface Comparator<WifiSSID>
{
int compare(WifiSSID obj1, WifiSSID obj2);
}
Your SortSSIDByid
comparator class will now implement java.util.Comparator
and that is what is required by the Collections.sort()
method.