The Collection root interface in the collection hierarchy, and is used to represent a group of elements. All classes that implement Collection have two constructors: a void constructor, which creates an empty collection, and a constructor with a single argument of type Collection, which creates a new collection with the same elements as its argument (making a copy).
Return | Method | Description |
---|---|---|
boolean | add(E e) | Ensures that element is in collection. |
boolean | addAll(Collection c) | Adds all of the elements in the specified collection to this collection. |
void | clear() | Removes all of the elements from this collection. |
boolean | contains(Object o) | Returns true if this collection contains the specified element. |
boolean | containsAll(Collection c) | Returns true if this collection contains all of the elements in the specified collection. |
boolean | equals(Object o) | Compares the specified object with this collection for equality. |
int | hashCode() | Returns the hash code value for this collection. |
boolean | isEmpty() | Returns true if this collection contains no elements. |
Iterator | iterator() | Returns an iterator over the elements in this collection. |
boolean | remove(Object o) | Removes a single instance of the specified element from this collection, if it is present. |
boolean | removeAll(Collection c) | Removes all of this collection’s elements that are also contained in the specified collection |
boolean | retainAll(Collection c) | Retains only the elements in this collection that are contained in the specified collection |
int | size() | Returns the number of elements in this collection. |
Object[] | toArray() | Returns an array containing all of the elements in this collection. |
T[] | toArray(T[] a) | Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
Optional implementation: add(), addAll(), clear(), remove(), removeAll(), and retainAll().
Required implementation: contains(), containsAll(), equals(), hashCode(), isEmpty(), iterator(), size(), toArray(), and toArray(T[] a).