Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

public class Main {
    public static void sortFileByDate(List<File> allFileList) {
        File[] files = new File[allFileList.size()];

        for (int i = 0; i < allFileList.size(); i++) {
            files[i] = allFileList.get(i);
        }

        Arrays.sort(files, new Comparator<File>() {
            public int compare(File f1, File f2) {
                return Long.valueOf(f1.lastModified()).compareTo(f2.lastModified());
            }
        });

        allFileList.clear();

        allFileList.addAll(Arrays.asList(files));
    }
}