Class TreeList<E>
- java.lang.Object
 - 
- java.util.AbstractCollection<E>
 - 
- java.util.AbstractList<E>
 - 
- org.apache.commons.collections4.list.TreeList<E>
 
 
 
 
- 
- All Implemented Interfaces:
 java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>
public class TreeList<E> extends java.util.AbstractList<E>AListimplementation that is optimised for fast insertions and removals at any index in the list.This list implementation utilises a tree structure internally to ensure that all insertions and removals are O(log n). This provides much faster performance than both an
ArrayListand aLinkedListwhere elements are inserted and removed repeatedly from anywhere in the list.The following relative performance statistics are indicative of this class:
get add insert iterate remove TreeList 3 5 1 2 1 ArrayList 1 1 40 1 40 LinkedList 5800 1 350 2 325ArrayListis a good general purpose list implementation. It is faster thanTreeListfor most operations except inserting and removing in the middle of the list.ArrayListalso uses less memory asTreeListuses one object per entry.LinkedListis rarely a good choice of implementation.TreeListis almost always a good replacement for it, although it does use slightly more memory.- Since:
 - 3.1
 
 
- 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int index, E obj)Adds a new element to the list.booleanaddAll(java.util.Collection<? extends E> c)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator.voidclear()Clears the list, removing all entries.booleancontains(java.lang.Object object)Searches for the presence of an object in the list.Eget(int index)Gets the element at the specified index.intindexOf(java.lang.Object object)Searches for the index of an object in the list.java.util.Iterator<E>iterator()Gets an iterator over the list.java.util.ListIterator<E>listIterator()Gets a ListIterator over the list.java.util.ListIterator<E>listIterator(int fromIndex)Gets a ListIterator over the list.Eremove(int index)Removes the element at the specified index.Eset(int index, E obj)Sets the element at the specified index.intsize()Gets the current size of the list.java.lang.Object[]toArray()Converts the list into an array.- 
Methods inherited from class java.util.AbstractList
add, addAll, equals, hashCode, lastIndexOf, subList 
 - 
 
 - 
 
- 
- 
Constructor Detail
- 
TreeList
public TreeList()
Constructs a new empty list. 
- 
TreeList
public TreeList(java.util.Collection<? extends E> coll)
Constructs a new empty list that copies the specified collection.- Parameters:
 coll- the collection to copy- Throws:
 java.lang.NullPointerException- if the collection is null
 
 - 
 
- 
Method Detail
- 
get
public E get(int index)
Gets the element at the specified index. 
- 
size
public int size()
Gets the current size of the list. 
- 
iterator
public java.util.Iterator<E> iterator()
Gets an iterator over the list. 
- 
listIterator
public java.util.ListIterator<E> listIterator()
Gets a ListIterator over the list. 
- 
listIterator
public java.util.ListIterator<E> listIterator(int fromIndex)
Gets a ListIterator over the list. 
- 
indexOf
public int indexOf(java.lang.Object object)
Searches for the index of an object in the list. 
- 
contains
public boolean contains(java.lang.Object object)
Searches for the presence of an object in the list. 
- 
toArray
public java.lang.Object[] toArray()
Converts the list into an array. 
- 
add
public void add(int index, E obj)Adds a new element to the list. 
- 
addAll
public boolean addAll(java.util.Collection<? extends E> c)
Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's Iterator.This method runs in O(n + log m) time, where m is the size of this list and n is the size of
c.- Specified by:
 addAllin interfacejava.util.Collection<E>- Specified by:
 addAllin interfacejava.util.List<E>- Overrides:
 addAllin classjava.util.AbstractCollection<E>- Parameters:
 c- the collection to be added to this list- Returns:
 trueif this list changed as a result of the call- Throws:
 java.lang.NullPointerException
 
- 
remove
public E remove(int index)
Removes the element at the specified index. 
 - 
 
 -