public class TreeList
extends java.util.AbstractList
List implementation 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 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 sligtly more memory.
| Constructor and Description |
|---|
TreeList()
Constructs a new empty list.
|
TreeList(java.util.Collection coll)
Constructs a new empty list that copies the specified list.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
java.lang.Object obj)
Adds a new element to the list.
|
void |
clear()
Clears the list, removing all entries.
|
boolean |
contains(java.lang.Object object)
Searches for the presence of an object in the list.
|
java.lang.Object |
get(int index)
Gets the element at the specified index.
|
int |
indexOf(java.lang.Object object)
Searches for the index of an object in the list.
|
java.util.Iterator |
iterator()
Gets an iterator over the list.
|
java.util.ListIterator |
listIterator()
Gets a ListIterator over the list.
|
java.util.ListIterator |
listIterator(int fromIndex)
Gets a ListIterator over the list.
|
java.lang.Object |
remove(int index)
Removes the element at the specified index.
|
java.lang.Object |
set(int index,
java.lang.Object obj)
Sets the element at the specified index.
|
int |
size()
Gets the current size of the list.
|
java.lang.Object[] |
toArray()
Converts the list into an array.
|
add, addAll, equals, hashCode, lastIndexOf, subListaddAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toStringpublic TreeList()
public TreeList(java.util.Collection coll)
coll - the collection to copyjava.lang.NullPointerException - if the collection is nullpublic java.lang.Object get(int index)
get in interface java.util.Listget in class java.util.AbstractListindex - the index to retrievepublic int size()
size in interface java.util.Collectionsize in interface java.util.Listsize in class java.util.AbstractCollectionpublic java.util.Iterator iterator()
iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listiterator in class java.util.AbstractListpublic java.util.ListIterator listIterator()
listIterator in interface java.util.ListlistIterator in class java.util.AbstractListpublic java.util.ListIterator listIterator(int fromIndex)
listIterator in interface java.util.ListlistIterator in class java.util.AbstractListfromIndex - the index to start frompublic int indexOf(java.lang.Object object)
indexOf in interface java.util.ListindexOf in class java.util.AbstractListpublic boolean contains(java.lang.Object object)
contains in interface java.util.Collectioncontains in interface java.util.Listcontains in class java.util.AbstractCollectionpublic java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in interface java.util.ListtoArray in class java.util.AbstractCollectionpublic void add(int index,
java.lang.Object obj)
add in interface java.util.Listadd in class java.util.AbstractListindex - the index to add beforeobj - the element to addpublic java.lang.Object set(int index,
java.lang.Object obj)
set in interface java.util.Listset in class java.util.AbstractListindex - the index to setobj - the object to store at the specified indexjava.lang.IndexOutOfBoundsException - if the index is invalidpublic java.lang.Object remove(int index)
remove in interface java.util.Listremove in class java.util.AbstractListindex - the index to removepublic void clear()
clear in interface java.util.Collectionclear in interface java.util.Listclear in class java.util.AbstractListCopyright © 2010 - 2023 Adobe. All Rights Reserved