Class IntList


  • public class IntList
    extends java.lang.Object
    A list of integer values that grows as necessary. Unlike List, IntList does not require each int to be boxed. This makes it helpful in use cases where storing Integer leads to excessive time spent in garbage collection.
    • Constructor Summary

      Constructors 
      Constructor Description
      IntList()
      Constructs a new IntList with a capacity of DEFAULT_INITIAL_CAPACITY.
      IntList​(int initialCapacity)
      Constructs a new IntList with the specified capacity.
      IntList​(IntList other)
      Constructs a new IntList that contains all the elements of the given IntList.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int value)
      Appends an int to the end of the list, growing the list if necessary.
      void clear()
      Empties the list.
      int get​(int index)
      Returns the indexth int in the list.
      boolean isEmpty()  
      int size()
      Accessor.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_INITIAL_CAPACITY

        public static final int DEFAULT_INITIAL_CAPACITY
        See Also:
        Constant Field Values
    • Constructor Detail

      • IntList

        public IntList​(int initialCapacity)
        Constructs a new IntList with the specified capacity.
        Parameters:
        initialCapacity - The number of ints that can be stored in this IntList before it will need to be reallocated.
      • IntList

        public IntList​(IntList other)
        Constructs a new IntList that contains all the elements of the given IntList.
        Parameters:
        other - the IntList to copy.
    • Method Detail

      • size

        public int size()
        Accessor.
        Returns:
        The number of ints currently stored in the list.
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if there are ints stored in the list.
      • clear

        public void clear()
        Empties the list. Note that this method does not shrink the size of the backing data store.
      • get

        public int get​(int index)
        Returns the indexth int in the list.
        Parameters:
        index - The list index of the desired int.
        Returns:
        The int at index index in the list.
        Throws:
        java.lang.IndexOutOfBoundsException - if the index is negative or greater than the number of ints stored in the list.
      • add

        public void add​(int value)
        Appends an int to the end of the list, growing the list if necessary.
        Parameters:
        value - The int to add to the end of the list.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object