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();
            
    
    
        }
    
    
    }
    

      

  • 相关阅读:
    WPF 依赖属性
    WPF 利用附加属性创建FreezableCollection集合和反射实现控件参数以MVVM模式传递
    VS Code 使用插件让HTML和JS代码运行在火狐浏览器
    WPF 键盘导航附加属性解决TreeView的Tab导航焦点问题
    WPF 透视相机的UpDirection(向上方向)
    ABP框架——集成Mysql
    CentOS7部署.Net Core2.0站点(中)
    CentOS7部署.Net Core2.0站点(上)
    (转)非常完善的Log4net详细说明
    GitHub for Windows提交失败“failed to sync this branch”
  • 原文地址:https://www.cnblogs.com/qianjinyan/p/10545082.html
Copyright © 2011-2022 走看看