There are few differences between HashMap and Hashtable. This example illustrates the key differences with simple example. Hashtable is synchronized where as HashMap is not synchronized. It is one of the key difference between HashMap and HashTable. HashMap offers better performance than HashTable in the multi-threaded environments. If you want to make HashTable thread-safe, use …
Java Collections
TreeSet in Java
TreeSet class implements the Set interface and stores the data in tree structure. The values are stored in sorted and ascending oreder. It is quite fast in retrieval of elements. This makes TreeSet is most prefered choice for storing the large amount of data in sorted order and want to retrieve it fast. This supports …
How To Sort Java Object Using Comparable And Comparator?
This tutorial shows how to use java.util.Comparator and java.lang.Comparable to sort a Java object based on its property value. Here I have created Employee object with Name and Age properties, we will be able to sort the list of objects based on the values in the property’ Lets look at the example. Employee.java ComparatorExample.java Output …
HashTable in Java
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. …
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. …