Collections

Cards (12)

  • The Java Collections Framework is a collection of interfaces and classes that may be used to manipulate groups of objects.
  • The classes implemented in the Java Collections Framework serve as reusable data structures and include algorithms for common tasks such as sorting or searching.
  • The framework uses parameterized classes so you can use them with the classes of your choice.
  • As far as manipulating collections is concerned, you may be reminded of the acronym CRUD.
    CRUD is short for Create, Read, Update, Delete.
  • The Collection interface is the highest level ofJava’s framework for collection classes and it describes the basic operations that all collection classes should implement.
  • public boolean add(Base_Type new Element)
    Adds the specified element to the collection.
    Returns true if the collection is changed as a result of the call.
  • public void clear ()
    Removes all of the elements from the collection.
  • public boolean remove(Object o)
    Removes a single instance of the specified element from the collection if it is present.
    Returns true if the collection is changed as a result of the call.
  • public boolean contains (Object o)
    Returns true if the specified element is a member of the collection.
  • public boolean isEmpty ()
    Returns true if the collection is empty.
  • public int size()
    Returns the number of elements in the collection.
  • public Object[] to Array ()
    Returns an array containing all of the elements in the collection.
    The array is of a type Object so each element may need to be type cast back into the original base type.