Java基础--LinkedList集合&HashSet集合

LinkedList集合的特点:

  1.底层是链表结构:查询慢,增删快

  2.里面含有大量操作首尾元素的方法

注意:使用linkedList集合的特有方法,不能使用多态

  添加元素 add()、push()、addLast()

  获取元素 getFirst()获取第一个元素、getLast()获取最后一个元素

  移除元素 removeFirst()、removeLast()、pop()移除第一个元素

 

HashSet集合:

  Set集合特点:

    元素不重复;没有索引,不能使用普通for循环遍历

  HashSet集合特点:

    元素不重复;没有索引,不能使用普通for循环遍历;无序集合;底层是哈希表结构(查询速度快)

 Set<Integer> set =new HashSet<>();
        set.add(1);
        set.add(2);
        set.add(3);
        set.add(2);
        //迭代器遍历set集合
        Iterator<Integer> it = set.iterator();
        while (it.hasNext()){
            Integer nx = it.next();
            System.out.println(nx);
        }
        //增强for循环遍历set集合
        for(Integer i:set){
            System.out.println(i);
        }

 

posted @ 2020-10-24 10:43  lemmon_water  阅读(150)  评论(0)    收藏  举报