当我执行 Collection.sort(List) 时,它将根据 String 的compareTo() 逻辑进行排序,其中它会逐个字符地比较两个字符串。
List<String> file1 = new ArrayList<String>();
file1.add("1,7,zz");
file1.add("11,2,xx");
file1.add("331,5,yy");
Collections.sort(file1);
我的理解是 char 意味着它指定 unicode 值,我想知道 char 的 unicode 值,例如,(逗号)等。我该怎么做?有任何 url 包含这些数值吗?
最佳答案
My understanding is char means it specifies the unicode value, I want to know the unicode values of char like ,(comma) etc
嗯,有一个从 char
到 int
的隐式转换,您可以轻松打印出来:
int value = ',';
System.out.println(value); // Prints 44
这是 char
的 UTF-16 代码单元。 (正如 fge 所指出的,Java 中的 char
是 UTF-16 代码单元,而不是 Unicode 字符。存在大于 65535 的 Unicode 代码点,它们表示为两个 UTF-16 代码单元。)
Any url contains the numeric value of these?
是 - 有关 Unicode 的更多信息,请访问 Unicode web site .
关于java char的unicode值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22735379/