Showing posts from November 23, 2010

Deque Interface

Deque Interface -
    Doubly ended queue is the concept of data structure in programming. Deque also called Doubly ended queue. Deque is extents Queue interface and define the structure of Doubly ended queue. Deque defines the functionality to delete data from both side first and last node.
    This interface defines methods to access the elements at both ends of the deque.
A list of methods are below :

 boolean add(E e) -
          Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

void addFirst(E e) -
          Inserts the specified element at the front of this deque if it is possible to do so immediately without violating capacity restrictions.

void addLast(E e) -
          Inserts the specified element at the end of this deque if it is possible…

Queue Interface

Queue Interface –
    In mathematical terms, there is an algorithm which introduce the FIFO (First in First out). Means if you are going to see a musical show, there will be a line of persons and one by one everybody will enter in the hall. It follows First in first out concept.
    Queue interface was introduced for follow the FIFO concept. Queue Interface came in J2SE 5.
    Declaration of Queue is
interface Queue<E>  

Queue interface has five methods:

E element() –
    This method is used for return an element which belongs at the head in Queue. If queue has no element it throws NoSuchElementException.

boolean offer(E e) -
    This method is used for adding a new element in queue. If queue adds this element it returns true otherwise return false.

E peek() –
    This method is used for return an element which belongs at the head in queue. If there is no element in queue, returns null.

E poll() –
    This method is used for delete an element at the head and returns the deleted element…

Comparator Interface

Comparator Interface -
    Comparator Interface is very essential in Java. If you have a group of some objects in a collection. And      you want to maintain order within these objects. Then you will need to implement Comparator Interface.

    It means Comparator Interface is used for managing the order within elements of any collection.

    Sorting order can be ascending order or descending order.

    There is another option for maintaining the shorting order. You can also short a collection through Comparable Interface. But Comparator interface has more generic and gives the facility that you can implement comparator interface in any class and compare any object.

    In the Comparator interface, compare method is exist. Signature of this method is :

public int compare(Object obj, Object obj1)

So you can compare two object which can be related to implementation class or can not.

Return type of compare method is int. It can return negative, positive or zero value.

Negative value indicates th…

SortedMap Interface

SortedMap Interface -
    SortedMap is an interface which extends Map Interface. SortedMap is important because it maintain the natural ascending order on its key. You can maintain another ordering through the Comparator interface on its creation time of SortedMap.
    It also has some extra method except Map Interface. You can find subMap, headMap, tailMap through the SortedMap Interface.

Now I am explaining the methods of SortedMap Interface.

Comparator<? super K> comparator() -
    This method gives the object of comparator if any ordering is maintaining on creation time. If Map has by default natural ascending order then it returns null.

SortedMap<K, V> subMap(K fromKey, K toKey) -
    This method is used to give the view of Map which is in range of fromKey and toKey. It will return empty map if range will not exactly match.

SortedMap<K, V> headMap(K toKey) -
    This method is used to give the view of map which belongs after the given key.

SortedMap<K, V> tailMa…

Map Interface

Map Interface -

Map Interface is another very essential object in Java.
Need of this object was to map an object with a key.

Map interface is used if you want to relate an object to a unique key.
So we can say, A Map is an object that maps keys to values. The important thing is that Map maintain only unique keys. If you will put same key then Map overrides this key.

you will find only last key with values.
    Map has three way to get values
    1) Get values through the keys
    2) Get Set of Keys and then get values.
    3) Get pair of keys and values.

Set Interface has some methods describes below -

 void clear() -
          Removes all keys and values from your map.

 boolean containsKey(Object key) -
           This method is used for returns true if this map has a key for
           the specified key.

 boolean containsValue(Object value) -
          This method is used for returns true if this map has one or more keys to the given value.

Set entrySet() -
          This method is used for return…

Recent Post

Recent Posts Widget