Class TreeList

  • All Implemented Interfaces:
    Iterable, Collection, List

    @Deprecated(since="2021-04-30")
    public class TreeList
    extends AbstractList
    Deprecated.
    Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.
    A 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.

    Since:
    Commons Collections 3.1
    • Constructor Detail

      • TreeList

        public TreeList()
        Deprecated.
        Constructs a new empty list.
      • TreeList

        public TreeList​(Collection coll)
        Deprecated.
        Constructs a new empty list that copies the specified list.
        Parameters:
        coll - the collection to copy
        Throws:
        NullPointerException - if the collection is null
    • Method Detail

      • get

        public Object get​(int index)
        Deprecated.
        Gets the element at the specified index.
        Specified by:
        get in interface List
        Specified by:
        get in class AbstractList
        Parameters:
        index - the index to retrieve
        Returns:
        the element at the specified index
      • size

        public int size()
        Deprecated.
        Gets the current size of the list.
        Specified by:
        size in interface Collection
        Specified by:
        size in interface List
        Specified by:
        size in class AbstractCollection
        Returns:
        the current size
      • listIterator

        public ListIterator listIterator​(int fromIndex)
        Deprecated.
        Gets a ListIterator over the list.
        Specified by:
        listIterator in interface List
        Overrides:
        listIterator in class AbstractList
        Parameters:
        fromIndex - the index to start from
        Returns:
        the new iterator
      • indexOf

        public int indexOf​(Object object)
        Deprecated.
        Searches for the index of an object in the list.
        Specified by:
        indexOf in interface List
        Overrides:
        indexOf in class AbstractList
        Returns:
        the index of the object, -1 if not found
      • add

        public void add​(int index,
                        Object obj)
        Deprecated.
        Adds a new element to the list.
        Specified by:
        add in interface List
        Overrides:
        add in class AbstractList
        Parameters:
        index - the index to add before
        obj - the element to add
      • set

        public Object set​(int index,
                          Object obj)
        Deprecated.
        Sets the element at the specified index.
        Specified by:
        set in interface List
        Overrides:
        set in class AbstractList
        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
      • remove

        public Object remove​(int index)
        Deprecated.
        Removes the element at the specified index.
        Specified by:
        remove in interface List
        Overrides:
        remove in class AbstractList
        Parameters:
        index - the index to remove
        Returns:
        the previous object at that index
      • clear

        public void clear()
        Deprecated.
        Clears the list, removing all entries.
        Specified by:
        clear in interface Collection
        Specified by:
        clear in interface List
        Overrides:
        clear in class AbstractList