gpt4 book ai didi

java - 试图找出排序的差异

转载 作者:太空宇宙 更新时间:2023-11-04 14:12:41 25 4
gpt4 key购买 nike

我必须验证表中的列是否已正确排序。我将列放入 Java 列表中并执行 Collections.sort() 忽略大小写。 Java排序与表的列排序不同。我注意到该表的排序方式与 Microsoft Excel 的排序方式相同。我试图找到差异,以便我可以正确地进行 Java 排序(也许是本地排序)。

我在 Windows 中的系统属性显示 en.us。无论如何,我以两种方式对角色进行了排序,并在下面向您展示。第一个是标准拉丁语,是 Java 排序。第二个,我不确定它到底是什么类型,是表格排序和Excel排序。任何人都可以弄清楚如何使 Java 排序与它匹配(一个区别是它使用我也需要的忽略大小写)。

== Collections.sort()

#   $   %   &   '   (   )   *   +   ,   -   .   /   0   1   2   3   4   5
6 7 8 9 : ; < = > ? @ A B C D E F G
H I J K L M N O P Q R S T U V W X Y
Z [ \ ] ^ _ ` a b c d e f g h i j k
l m n o p q r s t u v w x y z { | }

== Excel/表格排序

'   -   #   $   %   &   (   )   *   ,   .   /   :   ;   ?   @   [   \   ]   
^ _ ` { | } + < = > 0 1 2 3 4 5 6 7 8
9 A a B b C c D d E e F f G g H h I i
J j K k L l M m N n O o P p Q q R r S
s T t U u V v W w X x Y y Z z

最佳答案

来自:https://support.office.microsoft.com/en-ca/article/About-sorting-bfea8d83-145b-400f-9ecf-8f7189945185

Data analysis begins with sorting. You can sort text (A to Z or Z to A), numbers (smallest to largest or largest to smallest), and dates and times (oldest to newest and newest to oldest) in one or more columns. You can also sort by a custom list that you create (such as Large, Medium, and Small). Or you can sort by format, including cell color, font color, or icon set. Most frequently, you will sort by column, but you can also sort by rows.

When you sort, you rearrange data into some order. In contrast, when you filter, you hide extraneous data. For more information about filtering, see About filtering.

When you sort on a range of cells, the sort criteria aren't saved with your workbook. If you want to save sort criteria so that you can reapply it the next time that you open the workbook, you can save the data as a Excel table. Save your data in a table when you are sorting multiple columns or if you create complex sorting criteria that takes a long time to create.

When you reapply a sorting criteria, you may see different results. This can occur if values that are returned by a formula have changed and the sheet is recalculated. It can also occur if the range of cells or table column has had data added, changed, or deleted.

Excel sorts data by using the following ascending sort order: 0 1 2 3 4 5 6 7 8 9 (space) ! " # $ % & ( ) * , . / : ; ? @ [ \ ] ^ _ ` { | } ~ + < = > a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z FALSE TRUE (sheet errors) (blank cells).

因此排序顺序不会与 Collections.sort() 相同。由于 Java 很可能根据 UTF-8 对字符进行排序。

不确定 Excel 使用哪种编码,但您可以更改 Collections.sort() 的行为,如下所示:

Collator collector = Collator.getInstance(Locale.US);
collector.setStrength(Collator.PRIMARY);
Collections.sort(list, collector);

javadocs 中有很多关于此的文档。

关于java - 试图找出排序的差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28115477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com