1. 程式人生 > 遊戲 >恐怖主題動作射擊遊戲KINGDOM of the DEAD將在2022年1月上線PC

恐怖主題動作射擊遊戲KINGDOM of the DEAD將在2022年1月上線PC

package com.bo.collection;
//Collection
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class Demo01 {
public static void main(String[] args) {
//建立一個集合
Collection collection = new ArrayList();
//新增元素
collection.add("蘋果");
collection.add("西瓜");
collection.add("榴蓮");
System.out.println("元素個數:"+collection.size());
System.out.println(collection);
//刪除元素
collection.remove("蘋果");
System.out.println("刪除後元素個數:"+collection.size());
//清空元素
//collection.clear();
//System.out.println("清空元素後個數:"+collection.size());

//遍歷元素
System.out.println("---------------增強for----------");
for (Object object:collection) {
System.out.println(object);
}
System.out.println("------------迭代器(專門用來遍歷集合)--------------");
Iterator it=collection.iterator();
while(it.hasNext()){
String s =(String) it.next();
System.out.println(s);
//不能使用collection.remove()刪除方法
//it.remove();//刪除用it.remove
}
System.out.println("刪除之後:"+collection.size());
//判斷
System.out.println(collection.contains("西瓜"));//有沒有西瓜
System.out.println(collection.isEmpty());//是不是空的


}
}