码迷,mamicode.com
首页 > 其他好文 > 详细

Collection集合常用的功能

时间:2019-11-17 12:50:45      阅读:58      评论:0      收藏:0      [点我收藏+]

标签:功能   指定   oid   stat   方法   remove   接收   接口   集合   

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集合常用的功能

标签:功能   指定   oid   stat   方法   remove   接收   接口   集合   

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

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