美文网首页
集合中collection、List、LinkedList等特有

集合中collection、List、LinkedList等特有

作者: 半年很快 | 来源:发表于2018-06-22 20:34 被阅读0次

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<E> 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<E> listIterator()返回此列表元素的列表迭代器(按适当顺序)
ListIterator<E> listIterator(int index)
List<E> subList(int fromIndex, int toIndex) 包含开头,不包含结尾
E get(int index) 取指定下标的元素
5.删除全部对象:list.clear();

LinkedList特有的方法:
jdk1.6之前:
/addFirst()//始终在首位添加
//addLast()//始终在末尾添加
//getFirst()
//getLast()
//removeFirst()
//removeLast()
jdk1.6之后:
//offerFirst()
//offerLast()
//peekFirst()
//peekLast()
//pollFirst()
//pollLast()

相关文章

网友评论

      本文标题:集合中collection、List、LinkedList等特有

      本文链接:https://www.haomeiwen.com/subject/pqeueftx.html