21天精通java基础之Day12集合

    xiaoxiao2021-03-25  112

    Day12:集合。

    1.Collection  接口。

    |------List接口,存储有序的,可以重复的元素

            |------ArrayList,LinkedList(对于频繁的插入、删除操作),Vector(古老的实现类、线程安全的)

    |------Set 接口,存储无序的,不可重复的元素

            |------HashSet,LinkedHashSet,TreeSet

    |------Map接口,存储键值对的数据

            |------ HashMap,LinkedHashMap,TreeMap,HashTable(子类:Properties)

    2.List 方法与使用。

    |------ArrayList:List的主要实现类

         |-----void add(int index,Object ele) 在指定索引位置index添加ele元素。

         |-----int indexOf(Object obj) 返回obj在集合中首次出现的位置。没有返回-1

         |-----int lastIndexOf(Object obj) 返回obj在集合中最后一次出现的位置。没有返回-1。

         |-----List subList(int fromIndex,int toIndex)返回fromIndex到toIndex结束的一个子List。左闭右开

         

    3.集合的遍历 迭代器Iterator 的使用。

    |-----hasNext()如果仍有元素可以迭代,则返回true

    |-----next()

    方法1:while(iterator.hasNext()){}

    方法2:增强for循环,foreach

    转载请注明原文地址: https://ju.6miu.com/read-3779.html

    最新回复(0)