java相关知识点

Collections集合类

Collection :是集合类的上级接口,继承与他有关的接口主要有List和Set

Collections工具类:是针对集合类的一个帮助类,他提供一系列静态方法实现对各种集合的搜索、排序、线程安全等操作

eg1:Set集合是无序的,不重复,Map和List是有序的,可重复
**注**:Collections中的sort()方法可以直接为list和map排序
(1)为Set集合排序:

    List<File> cldList = fitsPkgService.findCldDirs(path);
    //使用set集合去除重复数据
    Set<String> monthSet = new HashSet();
    for (File file:cldList) {
        if(path.length() != putUrl.length()){
            String months = file.getName().substring(4,6);
            monthSet.add(months);
        }
    }
    //使用List存放Set中的值,方便排序
    List<String> list = new ArrayList<>();
    list.addAll(monthSet);
    
    //调用Collections的排序方法
    Collections.sort(list);

猜你喜欢

转载自my.oschina.net/u/3669033/blog/1817559