Class IntArray


  • public final class IntArray
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] array  
      private int size  
    • Constructor Summary

      Constructors 
      Constructor Description
      IntArray()  
      IntArray​(int capacity)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int i)
      Append an integer to the end of the array.
      int get​(int index)
      Read value from the array.
      int getSize()
      Returns the number of elements added to the array.
      void set​(int index, int value)
      Write a value to the specified index.
      int[] trim()
      Return a copy of the array, trimmed to fit the size of its contents exactly.
      • Methods inherited from class java.lang.Object

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

      • array

        private int[] array
      • size

        private int size
    • Constructor Detail

      • IntArray

        public IntArray()
      • IntArray

        public IntArray​(int capacity)
    • Method Detail

      • add

        public final void add​(int i)
        Append an integer to the end of the array.
        Parameters:
        i -
      • set

        public final void set​(int index,
                              int value)
        Write a value to the specified index. Assumes the array is already big enough.
        Parameters:
        index -
        value -
      • get

        public final int get​(int index)
        Read value from the array.
        Parameters:
        index - index into the array
        Returns:
        value at the specified index
      • getSize

        public final int getSize()
        Returns the number of elements added to the array.
        Returns:
        current size of the array
      • trim

        public final int[] trim()
        Return a copy of the array, trimmed to fit the size of its contents exactly.
        Returns:
        a new array of exactly the right length