Why Java Vector Class is Considered Obsolete or Unofficially Deprecated? or Why should I always use ArrayList over Vector

You should use ArrayList over Vector because you should default to non-synchronized access. Vector synchronizes each individual method. That’s almost never what you want to do. Generally you want to synchronize a whole sequence of operations. Synchronizing individual operations is both less safe (if you iterate over a Vector, for instance, you still need to … Read more

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