Java Unicode字符串排序 [英] Java Unicode strings sorting

查看:74
本文介绍了Java Unicode字符串排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,如何比较Unicode字符串?

In Java, how does Unicode strings get compared?

当我执行以下操作时,我的意思是说日语字符串:

What I mean is, if I have a few say, Japanese strings, when I do the following:

java.util.Arrays.sort(arrayOfJapaneseStrings);

如何比较和排序这些字符串?

how does those strings get compared and sorted?

推荐答案

默认情况下,字符串按Unicode顺序按字典顺序排序.该顺序是由UTF-16决定的,因此对于某些字符可能并不是您想要的,但是日语字符都在 BMP中,所以您应该不会有这些问题.

By default, Strings sort lexicographically, by Unicode order. The order is by UTF-16, so might not be exactly what you want for certain characters, but Japanese characters are all in the BMP, so you shouldn't have a problem with these.

如果您希望使用不同的排序顺序,则可以使用 java.text.Collat​​or 类定义不同的排序顺序.

If you would like a different sort order, you can use the java.text.Collator classes to define a different sort order.

这篇关于Java Unicode字符串排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆