zoukankan      html  css  js  c++  java
  • Java中的集合类,集合类有哪些,如何增添删除元素,如何遍历

    http://www.cnblogs.com/LittleHann/p/3690187.html

    import java.util.*;
    
    public class TestCollection {
    
        public static void main(String[] args) {
    
            Collection arrayList = new ArrayList();
            arrayList.add("====天晴朗=====");
            arrayList.add("====暖花儿朵朵绽放=====");
            arrayList.add("====暖花儿朵朵绽放=====");
            arrayList.add("====暖花儿朵朵绽放=====");
            arrayList.add("====暖花儿朵朵绽放=====");
            arrayList.add("====暖花儿朵朵绽放=====");
    
            System.out.println(arrayList);
            System.out.println(arrayList.size());
            Object[] objs = arrayList.toArray();
            for(int i = 0 ; i < objs.length ; i++){
                System.out.println(objs[i]);
            }
    
    
            Collection linkedList = new LinkedList();
            linkedList.add("====天晴朗=====");
            linkedList.add("====暖花儿朵朵绽放=====");
            linkedList.add("====暖花儿朵朵绽放=====");
            linkedList.add("====暖花儿朵朵绽放=====");
            linkedList.add("====暖花儿朵朵绽放=====");
            linkedList.add("====暖花儿朵朵绽放=====");
    
            System.out.println(linkedList);
            System.out.println(linkedList.size());
            Object[] linkedobjs = linkedList.toArray();
            for(int i = 0 ; i < linkedobjs.length ; i++){
                System.out.println(linkedobjs[i]);
            }
    
            Collection vector = new Vector();
            vector.add("====天晴朗=====");
            vector.add("====暖花儿朵朵绽放=====");
            vector.add("====暖花儿朵朵绽放=====");
            vector.add("====暖花儿朵朵绽放=====");
            vector.add("====暖花儿朵朵绽放=====");
            vector.add("====暖花儿朵朵绽放=====");
    
            System.out.println(vector);
            System.out.println(vector.size());
            Object[] vectors = vector.toArray();
            for(int i = 0 ; i < vectors.length ; i++){
                System.out.println(vectors[i]);
            }
    
    
            Collection hashSet = new HashSet();
            hashSet.add("====天晴朗=====");
            hashSet.add("====暖花儿朵朵绽放=====");
            hashSet.add("====暖花儿朵朵绽放=====");
            hashSet.add("====暖花儿朵朵绽放=====");
            hashSet.add("====33333=====");
            hashSet.add("=========");
            System.out.println(hashSet);
            System.out.println(hashSet.size());
            hashSet.remove("=========");
            System.out.println(hashSet);
            System.out.println(hashSet.size());
    
            //SortedSet是抽象的,不能被实例化
            //'SortedSet' is abstract; cannot be instantiated
            //Collection sortedset = new SortedSet();
    
            //EnumSet是抽象的,不能被实例化
            //'EnumSet' is abstract; cannot be instantiated
            //Collection enumset =new EnumSet();
            
    
    
        }
    
    
    }
    

      

  • 相关阅读:
    k8s的chart学习(上)
    k8s的应用打包工具Helm
    k8s通过configmap管理应用配置信息
    k8s通过secret管理敏感信息
    k8s的持久化存储PV&&PVC
    k8s的存储Volume
    使用python获取整月每一天的系统监控数据生成报表
    NGUI的UISprite动态染色的一种方法
    VS生成后事件对文件的copy以及更换扩展名
    【转】搞清楚脚本中这些函数的调用规律
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/10545082.html
Copyright © 2011-2022 走看看