JAVA基础总结(四) ----Collection集合类

本文总结了JAVA中Collection集合类的主要内容,包括List和Set的通用方法,详细介绍了Iterator接口及其实现原理,阐述了foreach遍历机制。同时,分别探讨了List接口(如LinkedList和Vector的区别)和Set接口(如HashSet和LinkedHashSet的特点),最后提到了Collections工具类的使用。
摘要由CSDN通过智能技术生成

JAVA基础总结(四) ----Collection集合类

一、Collection常用功能

java.util.collection

List 与 Set 的通用方法

	Collection<String> coll = new ArrayList<>();

	boolean bool1 = coll.add("abc"); //添加元素 

	boolean bool2 = coll.remove("abc"); //删除元素 成功返回true,不存在返回false
	boolean bool3 = coll.remove("124"); //false
	
	boolean bool4 = coll.contains("abc"); //判断是否包含

	boolean bool5 = coll.isEmpty(); //判断是否为空

	int size = coll.size(); //返回大小

	Object[] arr = coll.toArray(); //转换为数组

	coll.clear(); //清空所有元素,但不删除集合

Iterator接口:

java.util.Iterator

Collection coll = new ArrayList<>();

coll.add("a");
coll.add("b");
coll.add("c");

Iterator<String> it = coll.iterator();

while(it.haseNext()){ //
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值