Object-Oriented Programming (CS F213) : BITS Pilani
Object-Oriented Programming (CS F213) : BITS Pilani
Collections
Deque SortedSet
NavigableSet
<<abstract class>>
AbstractCollection
<<abstract class>>
AbstractCollection
<<abstract class>>
AbstractSet AbstractSequentialList <<abstract class>>
<<abstract class>>
AbstractCollection
<<abstract class>>
AbstractSet AbstractSequentialList <<abstract class>>
<<abstract class>>
AbstractCollection
Concrete Classes
11 Object-Oriented Programming (CS F213)
Collection Interface
interface Collection<E>
1. boolean add(E obj) Adds obj at the end of this collection
2. boolean addAll(Collection<? extends E> c) Adds all elements of c to the end of the
invoking collection.
3. void clear() Removes all elements of invoking collection and sets size =0
4. boolean contains(Object obj) Searches obj in invoking collection and returns true if
exists otherwise false
5. boolean containsAll(Collection<?> c) Returns true if all elements of collection c are
present in invoking collection
6. boolean equals(Object obj) Returns true if obj equals to the invoking collection,
otherwise false
7. boolean isEmpty() Returns true if size of the invoking collection is 0 otherwise false
8. Iterator<E> iterator() Helps to iterate the collection
9. boolean remove(Object obj) Removes the first occurrence of obj from the invoking
collection and returns true if successful otherwise false
10. boolean removeAll(Collection<?> c) Removes all the elements (if exists) of collection
c from the invoking collection and returns true if successful otherwise false
11. int size() returns the size of the collection
12. Object[] toArray() Stores the elements of the invoking collection in Object type array
and returns Object[].