zoukankan      html  css  js  c++  java
  • Java中Collection和Collections的区别

    1、java.util.Collection 是一个集合接口(集合类的一个顶级接口)。它提供了对集合对象进行基本操作的通用接口方法。Collection接口在Java 类库中有很多具体的实现。Collection接口的意义是为各种具体的集合提供了最大化的统一操作方式,其直接继承接口有List与Set。
     Collection   
    ├List   
    │├LinkedList   
    │├ArrayList   
    │└Vector   
    │ └Stack   
    └Set 
     
    2、java.util.Collections 是一个包装类(工具类/帮助类)。它包含有各种有关集合操作的静态多态方法。此类不能实例化,就像一个工具类,用于对集合中元素进行排序、搜索以及线程安全等各种操作,服务于Java的Collection框架。

    代码示例: 

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.List;
     
    public class TestCollections {
         
        public static void main(String args[]) {
            //注意List是实现Collection接口的
            List list = new ArrayList();
            double array[] = { 11211123456231 };
            for (int i = 0; i < array.length; i++) {
                list.add(new Double(array[i]));
            }
            Collections.sort(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
        }
    }
  • 相关阅读:
    更准确的mysql全文索引
    range
    牛顿冷却定律 使用
    Servo: The Embeddable Browser Engine
    Node.js V0.12新特性之性能优化
    Lodash,你正在使用的JavaScript库
    Python on Android
    Microsoft HoloLens 技术解谜(下)
    Microsoft HoloLens 技术解谜(上)
    市售体感设备横评
  • 原文地址:https://www.cnblogs.com/keyi/p/5816717.html
Copyright © 2011-2022 走看看