Posts

Showing posts with the label Interfaces

Map.Entry Interface

Map.Entry Interface -     Map.Entry Interface is used to hold the view of key-value pair from Map. Map interface has a method entrySet() which returns the Set object that holds the key value pair. You can iterate the key and value from getKey() and getValue(). You can also set value an element by the setValue() method. List of methods within the Map.Entry Interface -  boolean equals(Object o) -          This method is used to compares the specified object with this entry. If both are equal it return true otherwise return false.  K getKey() -     This method returns the key of map.  V getValue() -     This method returns the value of corresponding to this entry.  int hashCode() -     This method is used to return the hash code value for this map entry.  V setValue(V value) -     This method is used to set the values at  corr...

ListIterator Interface

ListIterator Interface -     ListIterator Interface is used for traverse list in both direction. You can find previous element by previous() method and next element by next() method. Within the both method ListIterator maintain the cursor position. ListIterator has previousIndex() for checking that List has previous index or not.      ListIterator Interface extends Iterator Interface. You can also set any new element in the list. List of methods within the ListIterator Interface - void add(E e) -     This method is used to add a given element into the list. boolean hasNext() -     This method is used to check the presence of element in the list when traversing the list in the forward direction. boolean hasPrevious() -     This method is used to check the presence of element in the list when traversing the list in the reverse direction. E next() -     this method is used to retu...

NavigableSet Interface

NavigableSet Interface -     NavigableSet Interface is very useful for searching strategics. NavigableSet Interface gives the functionality for closest search mechanism. NavigableSet may search less than, less than or equal, greater than or equal, and greater than through the lower, floor, ceiling, and higher methods. There is a example - import java.util.Iterator; import java.util.NavigableSet; import java.util.concurrent.ConcurrentSkipListSet; public class Test {     public static void main(String[] args) {             NavigableSet nSet = new ConcurrentSkipListSet();             nSet.add("A");             nSet.add("B");             nSet.add("C");             nSet.add("D");          ...

Iterator Interface

Iterator Interface -     Iterator Interface is used for retrieve the elements over the collection. Iterator Interface is similar to Enumeration Interface. Iterator Interface has one method extra for remove the elements from collection. Iterator Interface has three methods. boolean hasNext() -           This method is used for just check the presence of elements within the collection. If collection has elements, it returns true otherwise returns false. E next() -     This method is used to retrieve the view of element from the collection.      void remove() -     This method is used to delete elements from the collection which lastly return by the iterator.

Enumeration Interface

Enumeration Interface -     Enumeration interface used for retrieve the elements one by one from collection.     It makes a read only copy of objects and puts in enumeration. You can retrieve elements only.     Enumeration interface has two methods only. boolean hasMoreElements() -          This method is used to ensure that enumeration has elements or not. It return true if enumeration has elements otherwise return false. E nextElement() -     This method is used for retrieve the elements from enumeration. It throws NoSuchElementException if there is no element in enumeration. There are some classes which implements enumeration Interface. 1. StringTokenizer

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 ...

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 t...

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 ...

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 k...

SortedSet Interface

SortedSet Interface -     After making the Set interface, There was a need to make an interface which can hold the elements in natural ordering. And give some extra facilities except to set interface. Then SortedSet was wrote.     SortedSet Interface extends the Set Interface, maintain the sorting in ascending order. SortedSet is generic interface. And Sorted Interface has some extra methods. Comparator  comparator() - This method gives the object of Comparator interface, If any comparator is used for implementing this SortedSet. If SortedSet has natural order then returns null. Object first() - This method is used to return the first (lowest) element from the current set. Object last() - This method is used to return the last (highest) element from the current set. SortedSet subSet(Object start, Object end) -     This method is used to return the SortedSet, include elements those belongs between start and end-1 elements. SortedSet headS...

List Interface

List Interface –             List interface is used for storing element as a sequence.  It means List maintain the sequence according to inserted order. List interface extends the Collection interface. List maintains the index of all elements. So you can insert and retrieve elements by their index.             Keep in mind that list may contain duplicate elements.             List interface has its own methods which described below – void add(int index, Object obj) –             This method is used for insert element at given position into the List. Element which is already exist on the given index automatically shifted up. boolean addAll(int index, Collection c) –             This method adds all the object of ...

Set Interface

Set Interface -       Set is very important when you want to collect unique elements. Set is follows the mathematical  fundamental of Set. Set Interface can contains one null value also. But some implementation classes are not allowed the null value.     Set is not permitted two elements if both are equals. When any element is being added in set internally it check the element is already exist or not through equals and hashcode method. So Set override  equals and hashcode both method.     Set has no extra method. It extends Collection interface. So all method of collection interface is in the Set. But set interface restrict the duplicate elements.    There are some classes which implements the Set Interface. 1.AbstractSet 2.ConcurrentSkipListSet 3.CopyOnWriteArraySet 4.EnumSet 5.HashSet 6.JobStateReasons 7.LinkedHashSet 8.TreeSet               ...

Collection Interface

Collection Interface –     Collection Interface has arranged on top of the Collection Framework because any class within the Collection Framework must be implement.     Collection Interface also extends Iterable Interface so that any class can have use for-each loop for iterating the objects from Collection Interface.     Declaration of Collection Interface is :     interface Collection<E>         E denotes the data type of the objects which will store with in the Collection Interface Now we are providing the Methods List with description which is framed in Collection Interface. boolean add(Object obj) – This method is used for add news object in the Collection. This method returns false if Collection has this object already otherwise this method add the objects and return true. boolean addAll(Collection c) –     This method adds all the object of Collection c and return true,...

Recent Post

Recent Posts Widget