Showing posts with label java tutorials for webdriver. Show all posts
Showing posts with label java tutorials for webdriver. Show all posts

  • LinkedHashMap class is one of the class of map interface which extends HashMap class and implements Map interface.
  • It is combination of linked list and Hash table implementation of the Map interface and that's why it is called LinkedHashMap.
  • It is maintaining doubly-linked list insertion order in which keys were inserted into the map.
  • It allows to store null elements and optional Map operations are also available.
  • It is non synchronized implementation so if any thread modifies map structurally when map is accessed by multiple threads then it must be synchronized externally.

  • Is is pronounced as HashMap because It is hash table based implementation of map interface.
  • It extends AbstractMap class and implements Map interface.
  • It allows to store null key and null values.
  • It is non synchronized implementation so if multiple threads accessing it concurrently and any one of them modifies it then it must be synchronized externally.
  • It does not guarantee of maintaining the map order.

  • Java Map interface represents the mapping between unique keys to values.
  • Map can not hold duplicate values.
  • In Map interface, Each key can map at most one value.
  • Each Map interface provides three different collection views. Using which you can view map's content as a set of keys, collection of values and set of key-value mappings.
  • Map will helps you when you wants to search, update or delete elements based on it's key.
  • The map interface is implemented by different java classes like HashTable, HashMap and TreeMap.

  • Hashtable Class implements Map, Cloneable and Serializable interfaces and also extends Dictionary class.
  • It maps keys to values in table format. Every key is linked to it's value.
  • In Hashtable, any object which is non null will be used as a key or it's value.
  • Initial capacity and load factor are two parameters of Hashtable that affect its performance.
  • Meaning of capacity is the number of buckets in Hashtable and Meaning of initial capacity is number of buckets in Hashtable at the time of its creation.
  • Load factor is parameter which measure how much full Hashtable is and when to increase it's capacity automatically.
  • In order to successfully retrieve and store object in Hashtable, the object which is used as key must implement the equals and the hashCode methods.

  • TreeSet is class under Set interface of collection framework.
  • It implements NavigableSet interface which extends SortedSet interface.
  • Elements are ordered by a Comparator which is provided at set creation time or by natural ordering.
  • It maintains the ascending sorting order.
  • TreeSet is not synchronized so if multiple threads accessing it concurrently and any one modifies set entry then it must be synchronized externally.
  • Element's access and retrieval time is very fast from TreeSet so it will much useful when you wants to store large information in ascending order and retrieve any element quickly.
Java TreeSet Class hierarchy

  • SortedSet interface extends Set interface in collection framework of java.
  • As name suggest, It provides total ordering on elements of Set.
  • Set elements will be ordered using their natural ordering or using a comparator interface.
  • All the elements entries of SortedSet must implement Comparable interface.
  • All the elements of SortedSet must be comparable. So e1.compareTo(e2) must not throw ClassCastException.
  • In collection framework, TreeSet class is an implementation for the SortedSet interface.
Java SortedSet Interface hierarchy

  • HashSet is a class of collection framework which extends AbstractSet class and implements the Set interface.
  • HasSet doesn't guarantee that elements order will remain same over the time and returned in any random order.
  • HasSet doesn't allow duplicate values. If you try to insert duplicate, It will overwrite.
  • HasSet allows to store null values.
  • HasSet implementation is not synchronized.
Hashset hierarchy in Java Collection

  • LinkedHashSet Class extends extends HashSet class and Implements Set interface in collection interface hierarchy.
  • LinkedHashSet implementation differs from HashSet as it maintains doubly-linked list running through all of its entries.
  • It maintains element's entries in set as per it's insertion order. So it will allow you insertion order iteration over the set. So when you iterate over LinkedHashSet, In which order it will return elements? Answer is As per it's insertion order.
  • So you will get same copy of elements with the order how they inserted in set. 
  • LinkedHashSetis not synchronized.
LinkedHashSet Class hierarchy

  • Set is one of the collection framework interface which extends root Collections interface.
  • Set collection can not contain duplicate elements.
  • Set interface has all methods which are inherited from Collection interface with special restriction of not allowing duplicate elements.
  • If two Set interface contains same elements then both are equal.
  • Set interface is implemented by LinkedHashSet, HashSet classes and extended by SortedSet interface which is implemented by TreeSet.
Java Set Interface hierarchy

  • ArrayDeque is one of the collection framework member which implements Deque, Cloneable and Serializable interfaces.
  • ArrayDeque provides Resizable-array implementation so it has no capacity restrictions and it will grow as per requirement.
  • In the absence of external synchronization, they are not thread safe. So they do not allow multiple threads to access it concurrently.
  • Also ArrayDequenot allow to store null elements.
  • ArrayDeque Class is faster than LinkedList when used as a queue and faster than Stack when used as a stack.
  • If ArrayDeque is modified after the iterator creation and if it is not modified by iterators own method then it will throw ConcurrentModificationException. So in concurrent modification, Iterator will fail.
Java ArrayDeque Class hierarchy

  • Deque is one of the collection interface which extends Queue interface.
  • Deque is linear collection which allow us to add and remove element from both ends of the queue.
  • It is "double ended queue" that's why it is called Deque and usually pronounced as "deck".
  • Deque has different methods to perform insert, delete and examine the element in queue.
  • Each of these methods have two different forms. One will throw an exception if it fails during operation and other will return a special value like null or false.
java deque interface

  • PriorityQueue Class is one of the collection framework class which implements Queue, Serializable, Iterable and Collection interfaces.
  • It is using natural ordering to order then elements of PriorityQueue.Or elements will be ordered based on Comparator provided at queue construction time depending on which constructor is used.
  • PriorityQueue is based on a priority heap. Heap is tree based data structure where all the nodes of tree are in a specific order. Please read about Heap to learn how it works.
  • PriorityQueue does not allow non-comparable objects and it may throw ClassCastException if you will try to do so.
  • PriorityQueue does not allow null elements as well.
  • PriorityQueue implementation is not synchronized. So multiple threads should not access it concurrently.
Java PriorityQueue Class

  • If you look at collection hierarchy, Queue extends collection interface.
  • Main purpose of collection is to hold the elements prior to processing.
  • Queue interface provides some additional operations like insertion, inspection and extraction besides collection interface operations.
  • All these three operations exist in 2 different forms. One return special value(null or false depending on the operation) if operation fails else throws an exception if operation fails.
  • Queue follows FIFO(first-in-first-out) so it will insert element at the end of the queue when you insert new element and element will be removed from the beginning of the queue when you remove element.
  • As Queue interface is sub type of collection interface, all methods of collection interface are also available in Queue interface.
Queue Interface hierarchy

  • Stack class in java is one of the collection interface class which is subclass of Vector class.
  • Stake class supports usual push and pop operations.
  • In contrast to queue, Stack class has last-in first-out(LIFO) data structure. So item which is inserted at top will be available first.
  • Stack class extends Vector class of List interface so it includes all methods of vector class and also it has it's own several methods to perform push and pop operations like looking top item from stack, removing top item from stack, push new item at top of stack, searching item from stack and check whether stack is empty.
java stack class example

  • Vector class in java implements List interface of collection framework.
  • Vector class is synchronized.
  • If you don't know size of array then you can use vector class as size of vector can grow and shrink as per adding and removing items.
  • As vector class is synchronized, It will give poor performance on add, delete, update and search operations.
  • Elements of vector can be accessed using it's integer index.
vector class hierarchy in java

  • LinkedList class extends AbstractList class.
  • LinkedList class implements List and Deque interfaces.
  • LinkedList class is using doubly linked list to store elements in list.
  • LinkedList can hold duplicate elements in list.
  • LinkedList is non synchronized.
  • Manipulation is faster in linkedlist as shifting is not required when new element is inserted or deleted from list.
  • You can use it as list, stack or queue as it implements List and Deque interfaces of collection framework.

  • ArrayList class is sub class of collection interface which implements to List interface.
  • ArrayList class provides resizable-array so it can grow automatically as per requirement which resolves fixed Array limitation where you have to pre-define the size of array.
  • It can hold null elements too.
  • It is not synchronized implementation so if multiple threads accessing it concurrently and any one from them modifies the entry then it must be synchronized externally.
  • Also it can hold duplicate elements.
Java ArrayList Class hierarchy

What is Java Collections Framework?
Java Collections Framework is group of different interfaces, classes and algorithms. In simple word, Collection means single unit of objects and framework means good architecture. It is best architecture to store group of reusable objects and manipulate them. Collection framework has many different interfaces, their sub interfaces and classes, their classes and sub classes. All the interfaces and classes has different purpose. You can perform add, edit, delete, search, sort, etc operations on group of objects as per class's methods and implementation.

Java Collections Framework

Main Advantages Of Collection Framework
  • Main advantage of collection framework is it will reduces your programming efforts as there are ready made interfaces, classes and their methods which you can use directly in your program to perform operation on object collection. 
  • Collection is well structure framework so you code quality and speed will be increased.
  • Anyone can use collection very easily as it's interfaces, classes and methods very easy to understand and use.
Interfaces and Classes of Collection Framework
Collection, Set, List, Queue, Deque, SortedSet, Map and SortedMap are core interfaces of collection framework. Detailed description of collection framework's interfaces and it's classes is given on below given pages.


  • List interface in java is ordered collection so it can store elements in sequence.
  • List interface is sub interface and it extends to Collection interface.
  • List interface can hold duplicate elements so you can insert duplicate elements too.
  • You can access elements from list by integer index.
  • Collection framework has many interfaces in java and list interface is one of them.
  • List interface provides ListIterator to traverse through elements list in backward and forward directions.
List interface java

  • Collection is an interface in java.
  • Collection interface extends Iterable interface.
  • In hierarchy, Collection interface is root of List, Queue and Set interfaces.

Java Collection Interface

  • It represents unit of its elements. i.e. group of objects.
  • Some collections do not allow duplicate elements but some allows duplicate elements.
  • Collection interface is base on which collection framework is built.