zoukankan      html  css  js  c++  java
  • Collection与Collections的区别

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

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

    稍微举个例子:

    java代码

    public static void main(String args[]) {   
           //注意List是实现Collection接口的   
           List list = new ArrayList();   
           double array[] = { 112, 111, 23, 456, 231 };   
           for (int i = 0; i < array.length; i++) {   
               list.add(new Double(array[i]));   
           }   
           Collections.sort(list);   //把list按从小到大排序
           for (int i = 0; i < array.length; i++) {   
               System.out.println(list.get(i));   
           }   
           // 结果:23.0 111.0 112.0 231.0 456.0   
     }   

    然后还有混排(Shuffling)、反转(Reverse)、替换所有的元素(fill)、拷贝(copy)、返回Collections中最小元素(min)、返回Collections中最大元素(max)、返回指定源列表中最后一次出现指定目标列表的起始位置(lastIndexOfSubList)、返回指定源列表中第一次出现指定目标列表的起始位置(IndexOfSubList)、根据指定的距离循环移动指定列表中的元素(Rotate)

  • 相关阅读:
    负数求余数 C 和 Matlab&Python 处理不一样
    [Matlab] 线性卷积&圆周卷积代码实现
    [Arduino] 驱动RC522 读取 UID例程
    [C++] Nested Radical Constant
    [Arduino] 学习总结小合集(更新ING)
    谐振电路的品质因素总结
    142. Linked List Cycle II
    664. Strange Printer
    188. Best Time to Buy and Sell Stock IV
    50. Pow(x, n)
  • 原文地址:https://www.cnblogs.com/erfsfj-dbc/p/9949786.html
Copyright © 2011-2022 走看看