public class WindowsExplorerStringComparator extends Object implements Comparator<CharSequence>
此比较器模拟了 Windows 资源管理器的文件名排序方式,可得到与其相同的排序结果。
假设有一个数组,包含若干个文件名 {"abc2.doc", "abc1.doc", "abc12.doc"}
在 Windows 资源管理器中以名称排序时,得到 {"abc1.doc", "abc2.doc", "abc12.doc" }
调用 Arrays.sort(filenames);
时,得到 {"abc1.doc", "abc12.doc", "abc2.doc" }
调用 Arrays.sort(filenames, new WindowsExplorerStringComparator());
时,得到 {"abc1.doc", "abc2.doc",
"abc12.doc" }
,这与在资源管理器中看到的相同
Modifier and Type | Field and Description |
---|---|
static WindowsExplorerStringComparator |
INSTANCE
单例
|
Constructor and Description |
---|
WindowsExplorerStringComparator() |
Modifier and Type | Method and Description |
---|---|
int |
compare(CharSequence str1,
CharSequence str2) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public static final WindowsExplorerStringComparator INSTANCE
public int compare(CharSequence str1, CharSequence str2)
compare
in interface Comparator<CharSequence>
Copyright © 2024. All rights reserved.