Java集合之List
来源:互联网 发布:淘宝新店铺怎么做起来 编辑:程序博客网 时间:2024/05/04 09:12
List继承自Collection的接口,List也是集合的一种。List是有序队列,List中的没一个元素都会有一个索引,第一个元素的索引是0,往后的元素的索引值依次+1,List中允许有重复的元素。
List框架:
List接口源码:
public interface List<E> extends Collection<E> { int size();//大小 boolean isEmpty();//判断是否为空 boolean contains(Object o);//判断是否包含某个对象 Iterator<E> iterator();//返回迭代对象 Object[] toArray(); //返回对象数组 <T> T[] toArray(T[] a);//对象数组 boolean add(E e);//添加某个对象 boolean remove(Object o);//删除某个对象 boolean containsAll(Collection<?> c); // 是否包含某个Collection的所有对象 boolean addAll(Collection<? extends E> c);//将Collection对象追加到List中 boolean addAll(int index, Collection<? extends E> c);//在某个位置将Collection对象追加到List中 boolean removeAll(Collection<?> c);//去掉Collection中所包含的对象 boolean retainAll(Collection<?> c);//去掉不包含在Collection中所包含的对象 default void replaceAll(UnaryOperator<E> operator) { Objects.requireNonNull(operator); final ListIterator<E> li = this.listIterator(); while (li.hasNext()) { li.set(operator.apply(li.next())); } } @SuppressWarnings({"unchecked", "rawtypes"}) default void sort(Comparator<? super E> c) { Object[] a = this.toArray(); Arrays.sort(a, (Comparator) c); ListIterator<E> i = this.listIterator(); for (Object e : a) { i.next(); i.set((E) e); } } void clear();//删除所有对象 boolean equals(Object o);//判断两个list是否相同 int hashCode();//返回List的hashCode E get(int index);//返回某个位置的对象 E set(int index, E element);//替换某个位置的对象 void add(int index, E element);//在某个位置添加对象 E remove(int index);//删除某个位置的对象 int indexOf(Object o);//返回某个对象在List中的位置 int lastIndexOf(Object o);//List中最后一个对象的坐标 ListIterator<E> listIterator();//返回整个List的迭代 ListIterator<E> listIterator(int index); //从某个位置开始返回List的迭代 List<E> subList(int fromIndex, int toIndex);//截取部分List @Override default Spliterator<E> spliterator() { return Spliterators.spliterator(this, Spliterator.ORDERED); }}
1 0
- Java集合之List集合
- JAVA集合之List
- Java集合之List
- Java集合之List
- Java集合之List
- java集合之List
- java 集合之List
- Java集合之List
- Java之List集合
- Java之集合List
- Java集合之List
- Java集合之List
- 四大名捕-----JAVA集合之List
- java之List,Set集合
- java集合框架之list
- java集合类之List
- java集合框架之List
- java学习之List集合
- Java集合之Collection
- JAVA_SE系列: 08.java基本数据类型之整数类型
- 开个头·· 如何提高 Class imbalance DataSet的模型效果
- Myeclipse 安装Aptana
- JAVA_SE系列:09.java基本数据类型之浮点型
- Java集合之List
- hdu 1301 Jungle Roads
- leetcode 201: Bitwise AND of Numbers Range
- GridView如何让其子项充满
- JAVA_SE系列: 10.java基本数据类型之字符型与booleam型
- Java集合之Set
- HDU 4119 Isabella's Message (2011年成都赛区现场赛I题)
- Floyd算法的C&python实现及对比
- 线程