当前位置:网站首页>2.Collection接口

2.Collection接口

2022-08-09 09:23:00 过来我的小熊

Java Collection接口

Collection体系集合

graph TD;
	Interface.Collection-->Interface.List
	Interface.Collection-->Interface.Set
	Interface.List-->Class.ArrayList
	Interface.List-->Class.LinkedList
	Interface.List-->Class.Vector
	Interface.Set-->Class.HashSet
	Interface.Set-->Interface.SortedSet
	Interface.SortedSet-->Class.TreeSet

Interface(接口),Class(实现类)

该体系结构的根接口,代表一组对象,称为"集合"(Interface.Collection)

List接口的特点:有序,由下标,元素可重复

Set接口的特点:无序,无下标,元素不能重复

Collection父接口

特点:代表一组任意类型的对象,无序,无下标,不能重复

方法:

  • boolean add(Object obj) 添加一个对象
  • boolean addAll(Collection c) 将一个集合中的所有对象添加到此集合中
  • void clear() 清空此集合中的所有对象
  • boolean contains(Object o) 检查此集合中是否包含o对象
  • boolean equals(Object o) 比较此集合是否与指定对象相等
  • boolean isEmpty() 判断此集合是否为空
  • boolean remove(Object o) 在此集合中移除o对象
  • int size() 返回此集合中的元素个数
  • Object[] toArray() 将此集合转换成数组
  • iterator() 返回在此集合的元素上进行迭代的迭代器
    • hasNext() 判断是否存在下一个元素,返回boolean值
    • next() 获取下一个元素
    • remove() 删除当前元素
    • 不能同时使用collecton方法 ConcurrentModificationException 并发修改异常
原网站

版权声明
本文为[过来我的小熊]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_56121715/article/details/123747505