首页 > 其他 > 详细

Collection集合常用的功能

时间:2019-11-17 12:56:01      阅读:82      评论:0      收藏:0      [点我收藏+]
package demo06;

import java.util.ArrayList;
import java.util.Collection;

/*
* java.util
接口 Collection<E>
*
* 所有单列集合的最顶层接口,里面定义了所有单列集合共性的方法
* 任意的单列集合都可以使用Collection接口中的方法
* 共性方法
* boolean add(E e)
确保此 collection 包含指定的元素(可选操作)。
*
*
*
void clear()
移除此 collection 中的所有元素(可选操作)。
* */
public class demo06{
public static void main(String[] args) {
//创建一个集合对象 使用多态
Collection<String>coll=new ArrayList<>();
System.out.println(coll);//打印了空 重写了toString方法

/*
* public boolean add(E e) 把给定的对象添加到当前集合中;
* 返回值是一个boolean值,一般都返回true,所以可以不用接收;
* */
boolean b1=coll.add("张三");
System.out.println("b1"+b1);//b1true
System.out.println(coll);

// public boolean remove(E e);存在则删除返回true
boolean b2=coll.remove("张三");
System.out.println(coll);

}
}

Collection集合常用的功能

原文:https://www.cnblogs.com/Damocless/p/11875854.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!