1.集合 2.移除元素 3.迭代器 4.增强型for循环 5.编译器异常 6error错误 7.抛出异常
集合是java中提供的一种容器,可以用来储存多个数据
package demo01;
import java.util.ArrayList;
import java.util.Collection;
public class Demo01Collection {
public static void main(String[] args) {
Collection<String> coll= new ArrayList<>();
System.out.println(coll);
boolean b1=coll.add("张三");
System.out.println(b1);
System.out.println(coll);
coll.add("李四");
coll.add("李四");
coll.add("王五");
coll.add("赵六");
System.out.println(coll);
boolean b2=coll.remove("王五");
System.out.println(b2);
System.out.println(coll);
boolean b3=coll.contains("赵六");
System.out.println(b3);
boolean b4=coll.contains("王五");
System.out.println(b4);
boolean b5=coll.isEmpty();
System.out.println(b5);
int b6=coll.size();
System.out.println(b6);
Object[] arr=coll.toArray();
System.out.println(arr[0]);
System.out.println("=======");
coll.clear();
System.out.println(coll);
b5=coll.isEmpty();
System.out.println(b5);
}
}
异常分为抛出异常和捕获异常
package Demo02;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo01Exception {
public static void main(String[] args) {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-mm-dd");
Date date=null;
try {
date=sdf.parse("2021-05-11");
}catch(ParseException e) {
e.printStackTrace();
}
System.out.println(date);
int[] arr= {1,2,3};
System.out.println(arr[0]);
try {
System.out.println(arr[2]);
}catch(Exception e) {
System.out.println("第一句测试");
System.out.println(e);
}
int[]arr2=new int[1024*1024*1024*1024*1024];
System.out.println("后续代码");
}
}