码迷,mamicode.com
首页 > 编程语言 > 详细

JAVA 集合总结

时间:2020-02-20 09:26:01      阅读:86      评论:0      收藏:0      [点我收藏+]

标签:print   异常   date   查询   list   class   对象   安全   system   

ArrayList

  • 默认长度10
  • 底层是使用了Object数组实现
  • 查询快,增删慢,线程不安全
        ArrayList<Integer> list = new ArrayList<>();
        list.add(null);
        System.out.println(list.isEmpty());// false 添加null后,集合非空

迭代器

  • Iterator list.iterator() 返回当前集合的迭代器对象
  • Iterator.hasNext() 判断有无元素
  • Iterator.next()返回当前元素,索引后移
    *异常ConcurrentModificationException,迭代中不能操作原集合对象
        ArrayList<Object> arrayTest = new ArrayList<>();
        arrayTest.add("123");
        arrayTest.add(567);
        arrayTest.add(false);
        arrayTest.add(new Date());
        for (Iterator<Object> iterator2 = arrayTest.iterator();    //  返回当前集合的迭代器对象
                    iterator2.hasNext();)  //  判断有无元素
        {
                        //arrayTest.add("123");  //【ConcurrentModificationException】迭代中不能操作原集合对象
            System.out.println(iterator2.next());    //  返回当前元素,索引后移
        }

JAVA 集合总结

标签:print   异常   date   查询   list   class   对象   安全   system   

原文地址:https://www.cnblogs.com/xiongyungang/p/12334182.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!