Class TreeList<E>
- Type Parameters:
- E- the type of the elements in the list.
- All Implemented Interfaces:
- Iterable<E>,- Collection<E>,- List<E>
List implementation that is optimized 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 ArrayList and a LinkedList where 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     325
 
 
 ArrayList is a good general purpose list implementation.
 It is faster than TreeList for most operations except inserting
 and removing in the middle of the list. ArrayList also uses less
 memory as TreeList uses one object per entry.
 
 LinkedList is rarely a good choice of implementation.
 TreeList is almost always a good replacement for it, although it
 does use slightly more memory.
 
- Since:
- 3.1
- 
Field SummaryFields inherited from class java.util.AbstractListmodCount
- 
Constructor SummaryConstructorsConstructorDescriptionTreeList()Constructs a new empty list.TreeList(Collection<? extends E> coll) Constructs a new empty list that copies the specified collection.
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds a new element to the list.booleanaddAll(Collection<? extends E> c) Appends all 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.booleanSearches for the presence of an object in the list.get(int index) Gets the element at the specified index.intSearches for the index of an object in the list.iterator()Gets an iterator over the list.Gets a ListIterator over the list.listIterator(int fromIndex) Gets a ListIterator over the list.remove(int index) Removes the element at the specified index.Sets the element at the specified index.intsize()Gets the current size of the list.Object[]toArray()Converts the list into an array.Methods inherited from class java.util.AbstractListadd, addAll, equals, hashCode, lastIndexOf, removeRange, subListMethods inherited from class java.util.AbstractCollectioncontainsAll, isEmpty, remove, removeAll, retainAll, toArray, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.CollectionparallelStream, removeIf, streamMethods inherited from interface java.util.ListcontainsAll, isEmpty, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray
- 
Constructor Details- 
TreeListpublic TreeList()Constructs a new empty list.
- 
TreeListConstructs a new empty list that copies the specified collection.- Parameters:
- coll- the collection to copy
- Throws:
- NullPointerException- if the collection is null
 
 
- 
- 
Method Details- 
add
- 
addAllAppends all 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 interface- Collection<E>
- Specified by:
- addAllin interface- List<E>
- Overrides:
- addAllin class- AbstractCollection<E>
- Parameters:
- c- the collection to be added to this list
- Returns:
- trueif this list changed as a result of the call
- Throws:
- NullPointerException- if the specified collection contains a null element and this collection does not permit null elements, or if the specified collection is null
 
- 
clearClears the list, removing all entries.- Specified by:
- clearin interface- Collection<E>
- Specified by:
- clearin interface- List<E>
- Overrides:
- clearin class- AbstractList<E>
 
- 
containsSearches for the presence of an object in the list.- Specified by:
- containsin interface- Collection<E>
- Specified by:
- containsin interface- List<E>
- Overrides:
- containsin class- AbstractCollection<E>
- Parameters:
- object- the object to check
- Returns:
- true if the object is found
 
- 
get
- 
indexOf
- 
iterator
- 
listIteratorGets a ListIterator over the list.- Specified by:
- listIteratorin interface- List<E>
- Overrides:
- listIteratorin class- AbstractList<E>
- Returns:
- the new iterator
 
- 
listIteratorGets a ListIterator over the list.- Specified by:
- listIteratorin interface- List<E>
- Overrides:
- listIteratorin class- AbstractList<E>
- Parameters:
- fromIndex- the index to start from
- Returns:
- the new iterator
 
- 
remove
- 
setSets the element at the specified index.- Specified by:
- setin interface- List<E>
- Overrides:
- setin class- AbstractList<E>
- Parameters:
- index- the index to set
- obj- the object to store at the specified index
- Returns:
- the previous object at that index
- Throws:
- IndexOutOfBoundsException- if the index is invalid
 
- 
sizeGets the current size of the list.- Specified by:
- sizein interface- Collection<E>
- Specified by:
- sizein interface- List<E>
- Specified by:
- sizein class- AbstractCollection<E>
- Returns:
- the current size
 
- 
toArray
 
-