当前位置:网站首页>ComparisonChain-文件名排序
ComparisonChain-文件名排序
2022-06-28 19:52:00 【Yuyy】
实现Comparable接口
@Getter
@Setter
@Builder
@ToString
public class MyFile implements Comparable<MyFile> {
public Integer id;
private String name;
@Override
public int compareTo(MyFile other) {
//return this.id-other.id;
return ComparisonChain.start()
.compare(this.id,other.id)
.compare(this.name,other.name)
.result();
}
}遍历指定文件夹,并按照自定义规则排序
public class App {
public static void main(String[] args) {
File dir=new File("C:\\Users\\lenovo\\Desktop\\尚学堂Vue2.0");
File[] files=dir.listFiles();
List<MyFile> myFileList=new LinkedList<>();
if(files!=null){
for(File tmp:files){
if (!tmp.isFile()){continue;}
myFileList.add(MyFile.builder()
.id(Integer.valueOf(tmp.getName().substring(19,21).trim()))
.name(tmp.getName().substring(21).trim())
.build());
}
myFileList.sort(MyFile::compareTo);
Iterator iterator=myFileList.iterator();
while (iterator.hasNext()){
System.out.println(iterator.next());
}
}
}
}Post Views: 343
边栏推荐
- C#应用程序界面开发基础——窗体控制
- 秒杀系统设计
- From design delivery to development, it is easy and efficient!
- Demo of intelligent computing system 2 bangc operator development (heterogeneous programming flow of CPU and mlu270)
- Echart: category text position adjustment of horizontal histogram
- SQL server2019 create a new SQL server authentication user name and log in
- Grep text search tool
- 2022 P cylinder filling test exercises and online simulation test
- jsp中获取session中的值
- Day88. qiniu cloud: upload house source pictures and user avatars
猜你喜欢

Variable autoencoders (vaes)

easypoi

计网 | 一文解析TCP协议所有知识点

2022年T电梯修理考试题库模拟考试平台操作

Industry analysis - quick intercom, building intercom

Digital collection, ten thousand words long text, most of the questions you want to know have been clearly explained, which must be seen by practitioners

还在付费下论文吗?快来跟我一起白piao知网

阿里开源(EasyExcel)

H5 sunflower operation

Intelligent computing system 1 environment construction
随机推荐
Number theory -- detailed proof of Euler function, sieve method for Euler function, Euler theorem and Fermat theorem
2022年4月10日--使用C#迈出第一步--使用C#从.NET类库调用方法(没看懂)
2788.Cifera
How to learn JS through w3school / how to use the JS reference manual of w3school
Pipeline | and redirection >
2022 tea master (intermediate) examination simulated 100 questions and simulated examination
ArrayList of collection
2280.Cupboards
Industry analysis - quick intercom, building intercom
Past blue bridge cup test questions ants catch cold
30讲 线性代数 第四讲 线性方程组
Why is it not enough to declare the structure alias when using the structure variable of other files in C language, and the proper name must be used? (cannot add struct when using alias)
2342
Kettle (VI): full database backup based on kettle
From design delivery to development, it is easy and efficient!
TcWind 模式設定
Echart: category text position adjustment of horizontal histogram
还在付费下论文吗?快来跟我一起白piao知网
Head, tail view file
Quaternion quaternion and Euler angle Transformation in Ros