集合中collection、List、LinkedList等特有的方法
【集合中collection、List、LinkedList等特有的方法】Collection:
1.添加:boolean add(Object o) 、
boolean addAll(Collection extends E> c)
2.删除:boolean remove(Object o) 、
boolean removeAll(Collection> c)
3.判断:boolean contains(Object o)
boolean containsAll(Collection> c)
boolean isEmpty()
boolean equals(Object o)
4.获取---迭代器
Iterator
int size() //获取集合中对象的个数
5.集合变数组
Object[] toArray()
List特有的方法:
1.增:在某个位置增加
void add(int index, E element)
boolean addAll(int index, Collection extends E> c)
2.删:在某个位置删除
E remove(int index) E:代表的是一种数据类型
E remove(int index) E:代表的是一种数据类型
3.改: E set(int index, E element)
System.out.println(list.set(1, "haha"));
//返回值是被替换的元素
4.查:ListIterator
ListIterator
List
E get(int index) 取指定下标的元素
5.删除全部对象:list.clear();
LinkedList特有的方法:
jdk1.6之前:
/addFirst()//始终在首位添加
//addLast()//始终在末尾添加
//getFirst()
//getLast()
//removeFirst()
//removeLast()
jdk1.6之后:
//offerFirst()
//offerLast()
//peekFirst()
//peekLast()
//pollFirst()
//pollLast()
推荐阅读
- 热闹中的孤独
- Shell-Bash变量与运算符
- JS中的各种宽高度定义及其应用
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 深入理解Go之generate
- 异地恋中,逐渐适应一个人到底意味着什么()
- 图书集合完毕
- 我眼中的佛系经纪人
- 《魔法科高中的劣等生》第26卷(Invasion篇)发售
- “成长”读书社群招募