Java集合基本功能

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

import javax.swing.plaf.synth.SynthSpinnerUI;

/*
 * Collection:是集合的顶级接口,他的子体系有重复的,有唯一的,有有序的
 * Collection功能概述:
 * 1.添加功能:
 * 		boolean add(Object obj)添加一个元素
 * 		boolean addAll(Collection c)添加一个集合元素
 * 2.删除功能:
 * 		void clear()移除所有元素
 * 		boolean remove(Object obj)移除一个元素
 * 		boolean removeAll(Collection c)移除一个集合的元素
 * 3.判断功能:
 * 		boolean contains(Object obj)判断集合中是否包含指定元素
 * 		boolean containsAll(Collection c)判断集合中是否包含指定的集合元素
 * 		boolean isEmpty()判断集合是否为空
 * 4.获取功能
 * 		Iterator<E> iterator
 * 5.长度功能
 * 	    int size()元素个数
 * 6.交集功能
 * 		boolean retainAll(Collection c)两个集合都有哪些元素
 * 7.把集合转为数组
 * 		Object toArray()
 
 * 
 */
public class CollectionDemo {
	public static void main(String[] args) {
		//Collecttion c=new Collection();错误,接口不能实例化
		Collection c=new ArrayList();
		Collection c2=new ArrayList();
	//boolean add(Object obj)添加一个元素
	//boolean addAll(Collection c)添加一个集合元素
	c.add("hello");
	c.add("world");
	c.add("java");
	c2.add("hello");
	System.out.println(c);
	//boolean addAll(Collection c)添加一个集合元素
	//c.addAll(c);
	//System.out.println(c);
	//boolean remove(Object obj)移除一个元素
	//c.remove("hello");	
	//System.out.println(c);
	//boolean removeAll(Collection c)移除一个集合的元素
	//c.removeAll(c);	
	//System.out.println(c);
	//void clear()移除所有元素
	//c.clear();	
	//System.out.println(c);
	//boolean contains(Object obj)判断集合中是否包含指定元素
	//System.out.println(c.contains("hello"));
	//boolean containsAll(Collection c)判断集合中是否包含指定的集合元素
	//System.out.println(c.containsAll(c));
	//boolean isEmpty()判断集合是否为空
	//System.out.println(c.isEmpty());
	//int size()元素个数
	//System.out.println(c.size());
	//boolean retainAll(Collection c)两个集合都有哪些元素
	//System.out.println(c.retainAll(c2));
	//Object toArray()
	c.toArray();
	System.out.println(c);
	
	
	}

}














  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值