I have a requirement to sort objects (Zone) with their names (Zone Name: String), considering the case. I tried this with the Java Comparator interface.
class NameComparator implements Comparator<Zone> {
public int compare(Zone z1, Zone z2) {
return z1.getZoneName().compareTo(z2.getZoneName());
}
}
But this comparator sorts only lexicographically.
Ex: Required zone name order.
['Zone AAa3', 'Zone aaa3', 'Zone BBB7', 'Zone BBb7', 'Zone bbb7']
Current output:
['Zone AAa3', 'Zone BBB7', 'Zone BBb7', 'Zone aaa3', 'Zone bbb7']
Is there any way to achieve this other than writing a method to sort the source object?
source
share