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的底层数据结构基本就理解了全部集合。

  • 相关阅读:
    Date日期对象
    JAVA适配器
    java 对象的多态性
    简单轮播
    ecshop 教程地址
    瀑布流js排列
    phpcms 搜索结果页面栏目不显示解决 方法
    手机自动跳转
    字串符转换数字、取小数点后两位数的方法
    js 判断鼠标进去方向
  • 原文地址:https://www.cnblogs.com/shoulinniao/p/12702696.html
Copyright © 2011-2022 走看看