java西语,Java中字符串的传统西班牙语排序

I'm converting a .NET application into Java. The app reads in a file with this format:

es-MX

jueves

verde

amarillo

blanco

llave

llover

loma

cinco

domingo

rojo

but I'm having a trouble figuring out how to sort Spanish according to the traditional sorting of words. In VB.NET, you'd do see this:

Dim spainCultureTraditional As CultureInfo = New CultureInfo(&H40A)

but I can't find the equivalent traditional sorting locale in Java. The only difference between the two is that in es-MX/es-ES llave and llover would be switched versus the international sorting.

Note: the locale es-ES is not necessarily the same in Java and it is not the same in VB.NET.

解决方案

You might need customised Collation rules. There is a demo for tranditional Spanish here:

Summary code:

String smallnTilde = "\u00F1";

String capitalNTilde = "\u00D1";

String traditionalSpanishRules = (

"< a,A < b,B < c,C " +

"< ch, cH, Ch, CH " +

"< d,D < e,E < f,F " +

"< g,G < h,H < i,I < j,J < k,K < l,L " +

"< ll, lL, Ll, LL " +

"< m,M < n,N " +

"< " + smallnTilde + "," + capitalNTilde + " " +

"< o,O < p,P < q,Q < r,R " +

"< s,S < t,T < u,U < v,V < w,W < x,X " +

"< y,Y < z,Z");

RuleBasedCollator spCollator = new RuleBasedCollator(traditionalSpanishRules);

Collections.sort(words, spCollator);

System.out.println(words);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值