Java集合Collection
发布日期:2021-05-07 14:43:34 浏览次数:7 分类:原创文章

本文共 1150 字,大约阅读时间需要 3 分钟。

目录


集合体系结构【记忆】

集合类的特点:

  • 提供一种存储空间可变的存储模型,存储的数据容量可以随时发生改变

集合类的体系图:

2 Collection集合概述和基本使用【应用】

Collection集合概述:

  • 是单例集合的顶层接口,它表示一组对象,这些对象也称为Collection的元素
  • JDK 不提供此接口的任何直接实现,它提供更具体的子接口(如SetList)实现

Collection集合基本使用

public class CollectionDemo01 {    public static void main(String[] args) {//创建Collection集合的对象        Collection<String> c = new ArrayList<String>();//添加元素:boolean add(E e)        c.add("hello");        c.add("world");        c.add("java");//输出集合对象        System.out.println(c);    }}

 

3 Collection集合的常用方法【应用】

4 Collection集合的遍历【应用】

迭代器的介绍:
  • 迭代器,集合的专用遍历方式
  • Iterator iterator():返回此集合中元素的迭代器,通过集合的iterator()方法得到
  • 迭代器是通过集合的iterator()方法得到的,所以我们说它是依赖于集合而存在的

Collection集合的遍历:

public class IteratorDemo {    public static void main(String[] args) {//创建集合对象        Collection<String> c = new ArrayList<>();//添加元素        c.add("hello");        c.add("world");        c.add("java");        c.add("javaee");//Iterator<E> iterator():返回此集合中元素的迭代器,通过集合的iterator()方法得到        Iterator<String> it = c.iterator();//用while循环改进元素的判断和获取        while (it.hasNext()) {            String s = it.next();            System.out.println(s);        }    }}

 

集合使用步骤图解【理解】

使用步骤:

 
上一篇:Java集合List介绍和去重方案
下一篇:Java类和对象

发表评论

最新留言

关注你微信了!
[***.104.42.241]2025年04月04日 13时44分44秒