当前位置:网站首页>Comparisonchain file name sort
Comparisonchain file name sort
2022-06-28 20:10:00 【Yuyy】
Realization Comparable Interface
@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();
}
}Traverse the specified folder , And sort according to custom rules
public class App {
public static void main(String[] args) {
File dir=new File("C:\\Users\\lenovo\\Desktop\\ Shangxuetang 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
边栏推荐
- csdn涨薪技术-Selenium自动化测试全栈总结
- Analysis of all knowledge points of TCP protocol in network planning
- Software supply chain security risk guide for enterprise digitalization and it executives
- return new int[]{i + 1, mid + 1};return {i + 1, mid + 1};
- internship:术语了解及着手写接口
- echart:横向柱状图的类目文字位置调整
- 计网 | 一文解析TCP协议所有知识点
- 实型数运算
- 管道 | 与重定向 >
- redisTemplate
猜你喜欢

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

Markdown mermaid種草(1)_ mermaid簡介

Markdown drawing Mermaid practical tutorial

Analysis of all knowledge points of TCP protocol in network planning

Paper notes: universal value function approvers

Nanopc-t4 (rk3399) Game1 OLED (I2C) display time weather temperature

电子科大(申恒涛团队)&京东AI(梅涛团队)提出用于视频问答的结构化双流注意网络,性能SOTA!优于基于双视频表示的方法!...

Parallax JS special effect JS carousel map plug-in

bluecmsv1.6代码审计

数字藏品,万字长文,你想知道的大部分问题都讲清楚了从业者必看
随机推荐
Troubleshooting of pyinstaller failed to pack pikepdf
Nanopc-t4 (rk3399) Game1 OLED (I2C) display time weather temperature
Can layoffs really save China's Internet?
Day88. qiniu cloud: upload house source pictures and user avatars
Tcwind mode setting
odoo15 Module operations are not possible at this time, please try again later or contact your syste
Compression and decompression commands
TcWind 模式設定
Past blue bridge cup test questions ants catch cold
Head, tail view file
ComparisonChain-文件名排序
2837. The total number of teams
Analysis of all knowledge points of TCP protocol in network planning
easypoi
Ali open source (easyexcel)
Demo of integrated development of intelligent computing system 3 plugin
2280.Cupboards
集合之ArrayList
head、tail查看文件
ROS中quaternion四元数和欧拉角转换