zoukankan      html  css  js  c++  java
  • Collections

    package com.Collections;
    
    import java.util.ArrayList;
    import java.util.Collections;
    
    /*
     * Collections 操作集合的工具类,就好像Arrays是操作数组的工具类一样
     * 
     * 几个常用方法:
     *     binarySearch(Lsit l) 二分查找,前提是有序
     *     copy(Lsit dest,List src) 将所有元素从一个一个列表复制到另一个列表,目标列表的长度必须大于或者等于源列表,如果长了,不会影响后面的元素
     *     disJoint(Collection c1,Collection c2) 如果两个集合没有相同元素,返回true
     *     fill(List list,Object obj) 使用指定元素替换列表中的所有元素
     *     frequency(Collection c,Object o) 返回指定Collection中指定元素的数量
     *     indexOfSubList(List source,List target) 返回指定源列表中第一次出现指定目标列表的起始位置,没有返回-1
     *     LastIndexOfSubList(List source,List target)
     *     max(Collection c) 根据自然排序,返回Collection集合的最大元素
     *     min(Collection c)
     *     replaceAll(List list,T oldVal,T newVal) 使用另一个值替换列表中出现的所有某一指定值
     *     reverse(List) 反转指定列表
     *     rotate(List list,int distance) 根据指定距离轮换指定列表中的元素
     *     suffle(Lsit list) 随机置换列表元素
     *  sort(Lsit list)使用自然排序进行排序
     *  sort(List list,Compartor comparator)使用指定排序器对列表进行排序
     */
    public class Study01 {
        public static void main(String[] args) {
            ArrayList<Integer> al=new ArrayList<Integer>();
            al.add(12);
            al.add(23);
            al.add(32);
            al.add(23);
            al.add(13);
            al.add(98);
            System.out.println(al);
        //    ArrayList al2=new ArrayList();
    //        al2.add(13);
    //        Collections.copy(al, al2);
    //        System.out.println(al);
            //System.out.println(Collections.disjoint(al, al2));
    //        Collections.fill(al, 12);
    //        System.out.println(al);
    //        System.out.println(Collections.frequency(al, 23));
    //        System.out.println(Collections.max(al));
    //        Collections.sort(al);
    //        System.out.println(al);
    //        System.out.println(Collections.binarySearch(al, 23));
    //        Collections.rotate(al, 2);
    //        System.out.println(al);
            Collections.reverse(al);
            System.out.println(al);
        }
    
    }
    View Code
  • 相关阅读:
    基于LR的新闻文本分类
    NLTK最详细功能介绍
    11 Spark案例
    自然语言处理TF-IDF实践Demo
    NLP模型
    数据仓库
    SVN
    【E-26】ERROR: Could not install packages due to an EnvironmentError: [Errno 2] No such file or directory: '/opt/miniconda3/lib/python3.7/site-packages/mistune-0.8.4.dist-info/METADATA'
    【ML-7-2-1】聚类算法-KNN实践
    【E-25】ValueError: day is out of range for month
  • 原文地址:https://www.cnblogs.com/aigeileshei/p/5565982.html
Copyright © 2011-2022 走看看