What is the Difference Between Enumeration and Iterator Interface

Enumeration and Iterator are the interface available in java.util package. The functionality of Enumeration interface is duplicated by the Iterator interface. New implementations should consider using Iterator in preference to Enumeration. Iterators differ from enumerations in following ways: Enumeration contains 2 methods namely hasMoreElements() & nextElement() whereas Iterator contains three methods namely hasNext(), next(),remove(). Iterator … Read more

Difference between Vector and ArrayList? What is the Vector Class

Vector & ArrayList both classes are implemented using dynamically resizable arrays, providing fast random access and fast traversal. ArrayList and Vector class both implement the List interface. Both the classes are member of Java collection framework, therefore from an API perspective, these two classes are very similar. However, there are still some major differences between … Read more

Where will you use Hashtable and where will you use HashMap

  of possible future changes. In Java, both Hashtable and HashMap are implementations of the Map interface, and they are used to store key-value pairs. However, there are some differences between the two: Thread Safety: Hashtable is synchronized, which means it is thread-safe. Multiple threads can safely access a Hashtable concurrently. HashMap is not synchronized … Read more

How can we make Hashmap Synchronized

HashMap can be synchronized by Map m = Collections.synchronizedMap(hashMap); In Core Java, you can make a HashMap synchronized by using the Collections.synchronizedMap() method. This method returns a synchronized (thread-safe) map backed by the specified map. Here’s an example: java import java.util.Collections; import java.util.HashMap; import java.util.Map;public class SynchronizedHashMapExample { public static void main(String[] args) { // Creating … Read more

Why doesn’t Collection extend Cloneable and Serializable

From Sun FAQ Page: Many Collection implementations (including all of the ones provided by the JDK) will have a public clone method, but it would be mistake to require it of all Collections. For example, what does it mean to clone a Collection that’s backed by a terabyte SQL database? Should the method call cause … Read more