集合的继承结构
1.Collection接口
常用ArrayList和LinkList
2.Map接口
常用HashMap
3.Irerator接口
4.Collections工具类
LinkList
-
双向链表
-
相邻节点互相引用,收尾结点互相引用
-
两端效率高
-
创建:
LinkList<String> list=new LinkList<>();//<>中不能存放基本类型
-
方法:
add.get.size等 -
引用案例:丑数
-
使用Linklist创建3个集合
-
遍历
-
for(int i;i<list.size();i++){String s=list.get(i);System.out.printfln(s);}
ArrayList
- 内部封装一个数组,用数组存放数据,默认容量10
- 访问任意位置,效率高
- 增删数据效率低
- 创建:
ArrayList<Integer> list=new ArrayList<>();
- 方法:与LinkList相同,但是没有两端操作的方法
迭代器
- 辅助创建迭代器对象,来对当前集合进行遍历效率高
Iterator<String> it=list.iterator();
- 主要方法:hasNext.Next
- 遍历
while(it.hasNext()){String s=it.Next();System.out.println(s):}
异常
- 封装错误的信息
- 包括类型,提示消息,行号
- 继承结构:1.Error(系统级别错误,一般无法处理)2.Exception(可修复的错误)
捕获
try{//需要捕获的代码}catch(AException e){//处理方案}
throws
- 设置异常的抛出管道,想要抛出异常必须有对应的抛出管道
- RuntimeException有默认的管道,它与子类都可以从默认管道抛出
- throw是手动抛出异常,是动作