I am trying to sort my ArrayList, but when I check the first item in my supposedly sorted array, it is incorrect. I am not sure why? Am I missing anything?
Here is my Comparator:
package org.stocktwits.helper;
import java.util.Comparator;
import org.stocktwits.model.Quote;
public class NameComparator implements Comparator<Quote>
{
public int compare(Quote o1, Quote o2) {
return o1.getName().compareToIgnoreCase( o2.getName());
}
}
Here is how I perform the actual sort:
Collections.sort(quotes, new NameComparator());
Here is my test data
quotes = ["Yahoo", "Microsoft", "Apple"]
After sorting I want it to be:
quotes = ["Apple", "Microsoft", "Yahoo"]`
However when I pull out the first item after the sort, I get: "Yahoo"