java.util List and set
来源:互联网 发布:js中保留字的单词 编辑:程序博客网 时间:2024/05/29 21:28
List and Set are two interfaces which extends from the interface Collection.
1.List
List接口提供的适合于自身的常用方法均与索引有关,这是因为List集合为列表类型,以线性方式存储对象,可以通过对象的索引操作对象。
List接口的常用实现类有ArrayList和LinkedList,在使用List集合时,通常情况下声明为List类型,实例化时根据实际情况的需要,实例化为ArrayList或LinkedList
/***interface List is extends from the Collection, and add some functions which are related to the index. *and that's the List's most advantage. */public interface List<E> extends Collection<E>{// return the number of elements in this collection contains no elementsint size();// return true if this collection contains no elementsboolean isEmpty();//return true if this collection contains the specified elementsboolean contains(Object o);// return an Iterator over the elements in this collectionIterator<E> iterator();//return an array containing all of the elements in this collectionObject[] toArray();//<T> T[] toArray(T[] a);//add an elementsboolean add(E e);//remove an elementboolean remove(Object o);//Returns true if this collection contains all of the elements // in the specified collection.boolean containsAll(Collection<?> c);//adds all of the elements in the specified collection to this collectionboolean addAll(Collection<? extends E> c);//Removes all of this collection's elements that are also contained in the //specified collectionboolean removeAll(Collection<?> c);//Retains only the elements in this collection that are contained in the specified collectionboolean retainAll(Collection<?> c);//clear the collection remove all the elements from this collectionvoid clear();//Compares the specified object with this collection for equality.boolean equals(Object o);//returns the hash code value for this collection.//while the collection interface adds no stipulations to the general contract//for the Object.hashCode methos, programmers should take note that any class that override//the Object.equals method must also override the Object.hashCode method in //order to satisfy the general contract for the Object.hashCode method .//In particular, c1.equals(c2) implies that c1.hashCode == c2.hashCodeint hashCode();//addational//return the element at the specified position in this ListE get(int index);//replaces the element at the specified position in this List with// the specified element// and return the element previously at this positionE set(int index, E element);//inserts the specified element at the specified position in this List//Shifts the element currently at the position and any subsequent elements to right//adds one to their indicesvoid add(int index, E element);//remove the element at the specified position in the list//return the element previously at this positionE remove(int index);//search operation//Returns the index of the first occurrence of the specified element //in this list, or -1 if this list does not contain the element.int indexOf(Object o); /** * Returns the index of the last occurrence of the specified element * in this list, or -1 if this list does not contain the element. */ int lastIndexOf(Object o); // List Iterators /** * Returns a list iterator over the elements in this list (in proper * sequence). */ ListIterator<E> listIterator(); /** * Returns a list iterator over the elements in this list (in proper * sequence), starting at the specified position in the list. */ ListIterator<E> listIterator(int index); // View /** * Returns a view of the portion of this list between the specified * <tt>fromIndex</tt>, inclusive, and <tt>toIndex</tt>, exclusive. (If * <tt>fromIndex</tt> and <tt>toIndex</tt> are equal, the returned list is * empty.) The returned list is backed by this list, so non-structural * changes in the returned list are reflected in this list, and vice-versa. * The returned list supports all of the optional list operations supported * by this list.<p> * * This method eliminates the need for explicit range operations (of * the sort that commonly exist for arrays). Any operation that expects * a list can be used as a range operation by passing a subList view * instead of a whole list. For example, the following idiom * removes a range of elements from a list: * <pre> * list.subList(from, to).clear(); * </pre> * Similar idioms may be constructed for <tt>indexOf</tt> and * <tt>lastIndexOf</tt>, and all of the algorithms in the * <tt>Collections</tt> class can be applied to a subList.<p> * * The semantics of the list returned by this method become undefined if * the backing list (i.e., this list) is <i>structurally modified</i> in * any way other than via the returned list. (Structural modifications are * those that change the size of this list, or otherwise perturb it in such * a fashion that iterations in progress may yield incorrect results.) * * @param fromIndex low endpoint (inclusive) of the subList * @param toIndex high endpoint (exclusive) of the subList * @return a view of the specified range within this list * @throws IndexOutOfBoundsException for an illegal endpoint index value * (<tt>fromIndex < 0 || toIndex > size || * fromIndex > toIndex</tt>) */ List<E> subList(int fromIndex, int toIndex);}
Here we have a ListIterator which is an interface extends from the Iterator.
and the ListIterator is:
0 0
- java.util List and set
- java.util 中list ,set
- java Set and List part1
- java set and list part2
- java 遍历list、set时 删除元素 java.util.ConcurrentModificationException
- java.util包中 Set 和 List 的区别
- java.util包中 Set 和 List 的区别
- List, Set, Vector and Map in Java
- java.util.Set翻译
- java.util.Set翻译
- java.util.Set
- java.util.Set 排序
- java.util.Set<E>
- Set, List And Map
- java.util.List翻译
- java.util.List学习
- java.util.list操作
- java.util.List
- Linux下secureCRT串口传送文件
- java.util Iterable and Iterator
- awk命令详解
- Qt 翻译 多国语言 本地化。。。Step by Step
- ubuntu删除多余引导项
- java.util List and set
- 多线程下载JAVA代码移植到android 添加下载进度条跟踪
- Ubuntu在Dash主页找不到Startup Applications解决办法
- Linux sort uniq awk head 完成访问日志统计排序功能
- 针对Ubuntu更新后系统变慢的解决办法!
- MESSAGE Job found still running after platform shutdown. eclipse启动失败
- Windows2008R2如何安装framework 3.5
- 深入浅出设计模式 ------ Abstract Factory(抽象工厂)
- Grub2 grub.cfg详解