Collection Framework

Collection Framework introduced in java 1.2 and its improved a log in the latest versions of Java. Collections are available in java when its started. those are Vector, Stack, HashTable and Array, these are called legacy collection classes.

Collection : Collection is a root interface for the collection framework and it represents a group of objects as single unit. Collection interface consists all the common methods which are used to manipulate the collection(Group of objects).

Collection interface Methods:

  1. public boolean add(Object element) -> Used for insert the elements in a collection.
  2. public boolean addAll(Collection c) -> Used for insert the collection in to a collection.
  3. public boolean remove(Object element) -> Used for remove the specified element from the collection.
  4. public boolean removeAll(Collection c) -> Used for remove the specified collection from a collection.
  5. public boolean retainAll(Collection c) -> Remove the elements from the collection except specified collection.
  6. public int size() -> It return the total number of elements in a collection.
  7. public void clear() -> Removes all the elements from a collection.
  8. public boolean contains(Object element) -> Used for search given element present in a collection or not.
  9. public boolean containsAll(Collection c) -> Used for search a specified collection in a collection.
  10. public Iterator iterator() -> It returns the Iterator object.
  11. public Object[] toArray() -> Converts the collection into a Array.
  12. public boolean isEmpty() -> Used for check the collection is empty or not.
  13. public boolean equals(Object element) -> Used to compare the collection with other collection.
  14. public in hashCode() -> It return hashcode of a collection.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s