JAVA 容器常用类

奥利给,兄弟们给干了!
#容器
什么是容器?
在这里插入图片描述
容器又名集合 英文命 collection
collection 下又有两个接口 分别是无序接口 set和有序接口list
之后会分别讲到!
collection 常用类

  1. size() 判断容器中元素个数
  2. isEmpty 判断容器是否为空
  3. add 往容器中添加元素
  4. remove 移除给定元素
  5. clear 清空容器
  6. toArray 转出一个 object 数组
public class list {
public static void main(String[] args) {
	Collection<String> c=new LinkedList<String>();
	System.out.println("是否为空"+c.isEmpty());
	c.add("你好啊");
	c.add("好");
	System.out.println("元素个数"+c.size());
	System.out.println(c);
	c.remove("好");
	System.out.println(c);
	c.clear();
	System.out.println(c);
	Object []f = c.toArray();
	System.out.println(f);
	
}
}

在这里插入图片描述
在这里插入图片描述

发布了27 篇原创文章 · 获赞 5 · 访问量 658

猜你喜欢

转载自blog.csdn.net/qq_44620773/article/details/103856678
今日推荐