java – Collator plus Comparator

I have a bean collection optionitemdto (attribute tag and value), and I am now sorting by tag using such things:

Collections.sort(combo,new LabelComparator())

The problem is that it doesn't sort stressed vowels (my language environment is Spanish)

According to this document http://blogs.oracle.com/CoreJavaTechTips/entry/sorting_strings , I must use the collator class

But if I use collator sorting, I can't use comparator (and vice versa) Any ideas?

Thank you in advance!

Solution

Your labelcomparator should entrust collator to compare dto labels:

public int compare(OptionItemDTO dto1,OptionItemDTO dto2) {
    return collator.compare(dto1.getLabel(),dto2.getLabel());
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>