Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 按日期排序路径-实用程序方法_Java_Sorting_Path - Fatal编程技术网

Java 按日期排序路径-实用程序方法

Java 按日期排序路径-实用程序方法,java,sorting,path,Java,Sorting,Path,在一些包(如commons io、jodatime等)中是否有任何实用程序类,其中可以传入如下列表: March/Invoice - 00000020 - 01.03.2013.xls March/Invoice - 00000021 - 08.03.2013.xls April/Invoice - 00000025 - 05.04.2013.xls January/Invoice - 00000015 - 25.01.2013.xls 并按月份对路径进行排序,如: January/Invoi

在一些包(如commons io、jodatime等)中是否有任何实用程序类,其中可以传入如下列表:

March/Invoice - 00000020 - 01.03.2013.xls
March/Invoice - 00000021 - 08.03.2013.xls
April/Invoice - 00000025 - 05.04.2013.xls
January/Invoice - 00000015 - 25.01.2013.xls
并按月份对路径进行排序,如:

January/Invoice - 00000015 - 25.01.2013.xls
March/Invoice - 00000020 - 01.03.2013.xls
March/Invoice - 00000021 - 08.03.2013.xls
April/Invoice - 00000025 - 05.04.2013.xls

我们可以自己编写一个
比较器
,但我希望类似的东西已经存在于某个第三方库中?

类似的东西比搜索任何第三方库都好,我相信:

final Map<String, Integer> monthMap = new LinkedHashMap<String, Integer>();
// Initialize it with all the months and corresponding index like:
// (January,1), (February,2), etc...
monthMap.put("January", 1);
monthMap.put("February", 2);
monthMap.put("March", 3);
monthMap.put("April", 4);
monthMap.put("May", 5);
monthMap.put("June", 6);
monthMap.put("July", 7);
monthMap.put("August", 8);
monthMap.put("September", 9);
monthMap.put("October", 10);
monthMap.put("November", 11);
monthMap.put("December", 12);

Collections.sort(list, new Comparator<String>()
{
    @Override
    public int compare(String a, String b)
    {
        String first = a.substring(0, a.indexOf(File.separatorChar));
        String second = b.substring(0, b.indexOf(File.separatorChar));

        return monthMap.get(first).compareTo(monthMap.get(second));
    }
});
final Map monthMap=new LinkedHashMap();
//使用所有月份和相应的索引对其进行初始化,如:
//(1月1日),(2月2日)等。。。
一月一日;
2月2日;
三月三日;
四月四日;
五月五日;
普特月(“6月”,6日);
七月七日;
普特月(“8月”,8日);
九月九日(下称"九月"),;
10月10日;
11月11日;
12月12日;
Collections.sort(list,newcomparator()
{
@凌驾
公共整数比较(字符串a、字符串b)
{
String first=a.substring(0,a.indexOf(File.separatorChar));
String second=b.substring(0,b.indexOf(File.separatorChar));
返回monthMap.get(第一个).compareTo(monthMap.get(第二个));
}
});

我相信有比这更好的解决方案,它只是一个指针。

我不知道。使用一些Regexp和日历似乎很简单。你可以自己编写一个比较器。谢谢你的粗略示例。我重新做过,希望你不介意。