1.集合框架图
Collection 根接口
--List 接口 有序,有索引,可以存重复对象
--ArrayList 数组
--LinkedList 链表
--Vector 数组
--Set 接口 无序,无所以,不能存重复对象
--HashSet 哈希算法
--TreeSet 二叉树
2.Collection集合的基本功能测试
boolean add(E e) 增加元素
boolean remove(Object o) 删除元素
void clear() 删除所有元素
boolean contains(Object o) 是否包含元素
boolean isEmpty() 是否为空
int size() 集合元素个数
问题:字符串 数组 集合 获取长度?
"abc".length(); 字符串
arr.length; 数组
list.size(); 集合
3.集合的遍历之集合转数组遍历
Object[] toArray()
存入集合中的元素会自动类型提升
当使用存入集合中的对象的特有方法,我们要向下转型
问:String 怎么转 数组?
"abc".toCharArray(); String --> char[]
"abc".getBytes(); String --> byte[]
|
|