I was doing this sort first:
List<String> items = new ArrayList<String>();
Comparator<items> ignoreLeadingThe = new Comparator<items>() {
public int compare(String a, String b) {
a = a.replaceAll("(?i(^the\\s+", "");
b = b.replaceAll("(?i(^the\\s+", "");
return a.compareToIgnoreCase(b);
}
};
Collections.sort(items, ignoreLeadingThe);
now I am doing this:
ItemObject[] io = new ItemObject[items.size()];
Comparator<ItemObject> ignoreLeadingThe = new Comparator<ItemObject>() {
public int compare(ItemObject a, ItemObject b) {
a.name = a.name.replaceAll("(?i(^the\\s+", "");
b.name = b.name.replaceAll("(?i(^the\\s+", "");
return a.name.compareToIgnoreCase(b.name);
}
};
Arrays.sort(io, ignoreLeadingThe);
When I was sorting the ArrayList up top, it acted as normal; it ignored the “The ” and sorted list accordingly; but it wasn’t actually effecting the output of the list.
However, the bottom code when I am sorting a regular Array (filled with Objects and not Strings), actually remove “The “. For example, “The Joker”, would become “Joker”.
Does anyone see what is going wrong here?
As I stated in my comment,
… or just use one large expression. So, try something like this…