We can create a class extends Collator and override the compare method there.
An example is here.
public class MyCollator extends Collator {
@Override
public int compare(String source, String target) {
return source.compareTo(target);
}
@Override
public CollationKey getCollationKey(String source) {
// TODO Auto-generated method stub
return null;
}
@Override
public int hashCode() {
// TODO Auto-generated method stub
return 0;
}
}
Then we can use this newly added class to sort the String list, and it will display in a correct way.
Collator collator = new MyCollator();
Collections.sort(list, collator);
My Test Result is as follows:
- Rokiškis
- Salantai
- Skuodas
- Tauragė
- Telšiai
- Šakiai
- Šeduva
- Šiauliai
- Šilalė
Note, in the result, Š is displaying after T, this is because "Š".compareTo("T")>1 is equal to true.
I believe you can put some logic in compare method to make Š displaying just after S, but before T.
The above code is complied and executed using JDK 1.5 version.
Use Collections.sort(list) directly; You will get the same result as I mentioned above.