首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >顺序排序函数数值和日期

顺序排序函数数值和日期
EN

Stack Overflow用户
提问于 2022-04-07 23:23:39
回答 1查看 15关注 0票数 0

函数,该函数以数字顺序设置文件夹列表,然后按创建日期的顺序返回该列表。

4_Lemur_Jason_20250814_Text

3_Lemur_Jason_20221025_Text

6_Lemur_Jason_20200510_Text

=

第一列按数字顺序排列

3_Lemur_Jason_20221025_Text

4_Lemur_Jason_20250814_Text

6_Lemur_Jason_20200510_Text

=

创建日期的第二个列表

6_Lemur_Jason_20200510_Text

3_Lemur_Jason_20221025_Text

4_Lemur_Jason_20250814_Text

EN

回答 1

Stack Overflow用户

发布于 2022-04-07 23:44:20

我不太清楚整个问题是在问什么,尽管我相信您可以使用这样的方法来获取/排序文件名中的数字:

代码语言:javascript
复制
    Scanner fileScanner = new Scanner(new File("its location"));
    
    // create first/default
    int smallest = Integer.parseInt(
        fileScanner.nextLine().substring(0, 1));
    
    while(fileScanner.hasNextLine())
    {
        // reads only the digit
        int next = Integer.parseInt(
            fileScanner.nextLine().substring(0, 1));
        // replaces the digit if it's smaller
        smallest = (smallest > next) ? next : smallest; 
    }

强调这不是一个完整的解决方案,因为我不太清楚你要求的是什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71789988

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档