Java Srting中的集合类Collection(一)——List、set及集合中的重复元素判断方法

版权声明:转载注明来源。Keep Learning and Coding. https://blog.csdn.net/a771581211/article/details/88365863
package day03;

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

/**
 * java.util.Collection
 * 集合,用于存储一组元素。提供了维护集合的相关操作。
 * 其派生了两个子接口:
 * List:可重复集
 * Set:不可重复集
 * 元素是否重复是依靠自身equals方法比较的结果而定的。
 * @author kaixu
 *
 */
public class CollectionDemo1 {

	public static void main(String[] args) {
		Collection c = new ArrayList();
		/*
		 * boolean add(E e)
		 * 向集合中添加元素。
		 * 当元素成功添加到集合后返回true
		 */
		c.add("one");
		c.add("two");
		c.add("three");
		System.out.println(c);
		
		/*
		 * int size()
		 * 返回集合当中的元素个数
		 */
		System.out.println("size:"+c.size());
		
		/*
		 * boolean isEmpty()
		 * 判断当前集合是否不含有任何元素
		 * 即空集合
		 */
		boolean isEmpty = c.isEmpty();
		System.out.println("是否是空集:"+isEmpty);
		
		/*
		 * void clean()
		 * 清空集合元素
		 */
		c.clear();
		System.out.println("size:"+c.size());
		System.out.println("是否是空集:"+c.isEmpty());
	}

}

猜你喜欢

转载自blog.csdn.net/a771581211/article/details/88365863