zoukankan      html  css  js  c++  java
  • Java集合

     

    1.大boss接口Collection

    • boolean add(E e)
    • boolean addAll(Collection<? extends E> c)
    • void clear()
    • boolean contains(Object o)
    • boolean containsAll(Collection<?> c)
    • Iterator<E> iterator()
    • boolean remove(Object o)
    • boolean removeAll(Collection<?> c)
    • boolean retainAll(Collection<?> c) 仅保留此集合中包含在指定集合中的元素
    • int size()
    • Object[] toArray()

    2.迭代器Iterator

    这是一个接口,Collection继承了它,只有3个方法,hasNext()判断是否还有元素,next()获取当前的元素并移动到下一个位置,remove()从底层集合中删除此迭代器返回的最后一个元素,用来遍历的。实现如下

            ArrayList<Integer> list=new ArrayList<Integer>();
            list.add(10);
            list.add(33);
            Iterator it=list.iterator();
            while(it.hasNext()) {
                System.out.println(it.next());
            }

    它是以内部类的方式实现的,是依赖集合存在的,不同的集合容器存取方法不同,所以在各自类中用迭代器遍历的方法也不同。

    3.List有序(存储和取出顺序一致,数组就算是有序)、可重复。

    4.Set:元素不可重复

    查了不少博客,没啥人讲得详细,大概都是这几个方法,都是在子类中体现,理解了HashMapArrayListLinkedList的底层数据结构基本就理解了全部集合。

  • 相关阅读:
    python signal模块
    linux 下修改时间
    CentOS7关闭防火墙和SELinux
    centOS安装配置NFS
    python 调 java(胶水就是胶水)
    uuid
    python 最麻烦的时间有药了
    linux crontab
    Linux awk+uniq+sort 统计文件中某字符串出现次数并排序
    trove taskmanger api
  • 原文地址:https://www.cnblogs.com/shoulinniao/p/12702696.html
Copyright © 2011-2022 走看看