HashTable class was originally added as part of java.utill package and extended the Dictionary class. From Java 2, it is re-engineered to implement the Map interface and made as part of the collections framework. HashTable is similar to HashMap except that HashTable is synchronized. It is very much similar to HashMap, stores the key-value pairs. …
Java Basics
HashMap in Java
HashMap uses the hash table to implement the Map interface. Map is key-value pair where key is the reference and value is the actual data. HashMap is very extensively used in the projects when key-value type data is stored. This doesn’t ensure the order of insertion. This class extends the AbstractMap and implements the Map …
HashSet in Java
HastSet is one of the classes available with collections package and it extends the AbstractSet and implements the Set interface. This uses the hash table for storing the values. Hash table internally using hashing mechanism to store the values. In the hashing technique, information is uniquely identified using the hash code. HashSet supports four constructors. …
LinkedList in Java
LinkedList is not most commonly used class for storing the values. The LinkedList class extends AbstractSequentialList and implements the List interface. It stores the data using linked-list data structure. This class has two constructors, With empty parameters – LinkedList() and With Collection object as the parameter – LinkedList (Collection c) Some of the important features of …
ArrayList in Java
ArrayList is most widely used collections API for storing the list of objects. This class is equivalent to Vector, except that it is unsynchronized. Look at the below important points about the class ArrayList. It allows null values It stores the duplicate elements The size of the list is grows dynamically when more elements are …
Difference Between Throw and Throws in Exception Handling
When you are working with exception handling in Java, use of throw and throws may confuse you if you not familiar with the exception handling. Both are important keywords used frequently used in handling the exceptions. Throw is used for explicitly throwing an exception. Throw attribute in method signature, is a hint to the compiler …
Try, Catch and Finally in Exception Handling
The basic procedure to handle the exception is to use the try-catch block. If you want to put any code that would cause a exception, then write that piece of code inside the try-catch block. If you expect multiple type of exceptions in the same block, then you can write more than one catch block …
Constructor in Java
Constructors are special type of methods that are invoked at the time of creating the objects. If you use new keyword for creating the object, the constructors are called. There are certain restrictions imposed on these special type of methods. Constructors should have the same name as class name Constructors should not have any return …