Class IntSet


  • public class IntSet
    extends java.lang.Object
    Class for storing a set of integers
    • Constructor Summary

      Constructors 
      Constructor Description
      IntSet​(int capacity)
      Constructs a new empty int set
      IntSet​(int[] values)
      Constructs a new IntSet and populates it with the given array of ints.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void add​(int value)
      Add the int value to the set.
      void clear()
      Removes all values from the set.
      boolean contains​(int value)
      Returns true if the set contains the given value.
      int[] getValues()
      Returns an array with all the values in the set.
      boolean isEmpty()
      Returns true if the set is empty
      boolean remove​(int value)
      Removes the int value from the set.
      int size()
      Returns the number of ints in the set.
      • Methods inherited from class java.lang.Object

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

      • IntSet

        public IntSet​(int capacity)
        Constructs a new empty int set
        Parameters:
        capacity - the initial storage size, the set will grow if needed.
      • IntSet

        public IntSet​(int[] values)
        Constructs a new IntSet and populates it with the given array of ints.
        Parameters:
        values - the array if ints to add to the set.
    • Method Detail

      • size

        public int size()
        Returns the number of ints in the set.
        Returns:
        the number of ints in the set.
      • isEmpty

        public boolean isEmpty()
        Returns true if the set is empty
      • contains

        public boolean contains​(int value)
        Returns true if the set contains the given value.
        Parameters:
        value - the value to test if it is in the set.
        Returns:
        true if the value is in the set.
      • add

        public void add​(int value)
        Add the int value to the set.
        Parameters:
        value - the value to add to the set.
      • remove

        public boolean remove​(int value)
        Removes the int value from the set.
        Parameters:
        value - the value to remove from the set.
        Returns:
        true if the value was in the set, false otherwise.
      • clear

        public void clear()
        Removes all values from the set.
      • getValues

        public int[] getValues()
        Returns an array with all the values in the set.