Support Me ��


SUBSCRIBE NOW

Collection Framework in JAVA 2


Collection Framework in JAVA 2

Interfaces of Collection Framework

The collection framework has a lot of Interfaces, setting the fundamental nature of various collection classes. Lets study the most important Interfaces in the collection framework

The Collection Interface

1. It is at the top of collection heirarchy and must be implemented by any class that defines a collection. Its general declaration is,

interface Collection < E >

2. Following are some of the commonly used methods in this interface.

 Methods Description
 add( E obj ) Used to add objects to a collection. Doesn't add duplicate elements to the collection
 addAll( Collection C ) Add all elements of collection C to the invoking collection
 remove( Object obj ) To remove an object from collection
 removeAll( Collection C ) Removes all element of collection C from the invoking collection
 contains( Object obj ) To determine whether an object is present in collection or not
 isEmpty() Returns true if collection is empty, else returns false
 equals( Object obj ) Returns true if two collections matches, else returns false
 size() Returns total number of elements present in collection
 clear() Removes total number of elements from collection

 

The List Interface

1. It extends the Collection Interface, and defines storage as sequence of elements. Following is its general declaration,

interface List < E >

2. Allows random access and insertion, based on position.

3. It allows Duplicate elements.

4. Apart from methods of Collection Interface, it adds following methods of its own.

 Methods Description
 get( int index ) Returns object stored at the specified index
 set( int index, E obj) Stores object at the specified index in the calling collection
 indexOf( Object obj ) Returns index of first occurence of obj in the collection
 lastIndexOf( Object obj ) Returns index of last occurence of obj in the collection
 subList( int start, int end ) Returns a list containing elements between start and end index in the collection

 

The Set Interface

1. This interface defines a Set. It extends Collection interface and doesn't allow insertion of duplicate elements. It's general declaration is,

interface Set < E >

2. It doesn't define any method of its own. It has two sub interfaces, SortedSet and NavigableSet.

3. SortedSet interface extends Set interface and arranges added elements in an ascending order.

4. NavigabeSet interface extends SortedSet interface, and allows retrieval of elements based on the closest match to a given value or values.


The Queue Interface

1. It extends collection interface and defines behaviour of queue, that is first-in, first-out. It's general declaration is,

interface Queue < E >

2. There are couple of new and interestin methods added by this interface. Some of them are mentioned in below table.

 Methods Description
 poll() removes element at the head of the queue and returns null if queue is empty
 remove() removes element at the head of the queue and throws NoSuchElementException if queue is empty
 peek() returns the element at the head of the queue without removing it. Returns null if queue is empty
 element() same as peek(), but throws NoSuchElementException if queue is empty
 offer( E obj ) Adds object to queue.

 

The Dequeue Interface

1. It extends Queue interface and declares behaviour of a double-ended queue. Its general declaration is,

interface Dequeue < E >

2. Double ended queues can function as simple queues as well as like standard Stacks.

Dinesh Kumar S is a 23-year-old System Administrator who enjoys playing games, listening to music and learning new technology. He is friendly and generous, but can also be very lazy and crazy.

Share this

Backlinks

Website Design Company in Coimbatore
Website Design Company in Tamil nadu
Website Design Company in Karur
Website Design Company in Erode
Website Design Company in ooty
Website Design Company in theni
Website Design Company in thoothukudi
Website Design Company in Chennai
Website Design Company in Sathy
Website Design Company in Coimbatore Tamilnadu
Cheap Website Design Company in Coimbatore
Adsense Website Design Company in Coimbatore
ecommerce Website Design Company in Coimbatore
school Website Design Company in Coimbatore
Academy Website Design Company in Coimbatore
Test Website Design Company in Coimbatore
Best Website Design Company in Coimbatore
Adsense Website Design Company in Coimbatore
Adsense Website Design Company in Tamil nadu
Adsense Website Design Company in Karur
Adsense Website Design Company in Erode
Adsense Website Design Company in ooty
Adsense Website Design Company in theni
Adsense Website Design Company in thoothukudi
Adsense Website Design Company in Chennai
Adsense Website Design Company in Sathy
Free SEO Tools online
Free SEO Tools online Website
Free SEO Tools online Plagiarism
Free SEO Tools online article rewriter tool
Free SEO Tools online article reading and writing criticism
Free SEO Tools online seo backlink
Free SEO Tools online Free backlink maker
Free SEO Tools online seo backlink strategy
Free SEO Tools online content writting
360 help SEO Tools online Plagiarism checker
360 help SEO Tools online seo backlink
360 help SEO Tools online Free backlink maker
360 help SEO Tools online content writting
360 help SEO Tools online article rewriter tool
360 help SEO Tools
360 help SEO Tools India
360 help SEO Tools Tamil
360 help SEO Tools website