JAVA排序

对于JAVA排序需要实现Comparator接口,来指定按什么顺序来排序,集合类用Collections.sort方法,数组用Array.sort方法,默认按升序排序

public class Music {

    private String filename;

    private String title;

    private int during;

    private String singer;

    private String type;

    private String size;

    private String fileUrl;
public class Mycomparator implements Comparator<Music>{



    @Override

    public int compare(Music arg0, Music arg1) {

        // TODO Auto-generated method stub

        return (arg0.getFilename().toLowerCase()).compareTo(arg1.getFilename().toLowerCase());

    }

}
Collections.sort(allsongs,new Mycomparator());

allsongs是一个List集合

你可能感兴趣的:(Java排序)