Constructor Overloading in Java

Constructor are used to create the objects . new keyword always calls the  constructor of the class.  Constructor name is always be the same as the name of the class .Generally in 99% code ,the name of the method is  different from the name of the class . But the problem arises  that method  too can…

Read More

Fail Fast Vs Fail Safe Iterator In Java

Fail fast iterator while iterating through the collection , instantly throws Concurrent Modification Exception if there is structural modification  of the collection.  Fail Safe Iterator makes copy of the internal data structure (object array) and iterates over the copied data structure.Any structural modification done to the iterator affects the copied data structure. Fail Fast Iterator Fail Safe Iterator…

Read More

Iterable interface in Java

The Iterable Interface is defined in java.lang package. The Iterable interface is the super interface in collection framework. It is the root interface for all the collection classes. The Collection interface extends the Iterable interface. So,all the subclasses that implementing the Collection interface also implement the Iterable interface. Implementing this interface allows an object to be the target of the enhanced “for each” statement. The for-each loop is used…

Read More

Iterator vs ListIterator in Java

Iterator ListIterator Can traverse all the collections including set, map, etc. It can be used to traverse only list type collection like ArrayList, LinkedList. Iterates the collection only in the forward direction. Can iterate over the collection in forward as well as backward direction. Cannot obtain indexes. Can obtain indexes. No way to add new elements…

Read More

Iterator Interface in Java

In Java, an Iterator is a construct that is used to traverse or step through the collection. In order to use an Iterator, you need to get the iterator object using the iterator() method of the collection interface. Java Iterator is a collection framework interface and is a part of the java.util package. Using Java Iterator we…

Read More

HashMap in Java

Here is the list of methods available in HashMap class. I have also covered examples using these methods at the end of this post. void clear(): It removes all the key and value pairs from the specified Map. Object clone(): It returns a copy of all the mappings of a map and used for cloning them…

Read More