Synchronized resizable-array implementation of the List interface is _____________?
-
Vector
-
ArrayList
-
Hashtable
-
HashMap
Vector is a legacy class (introduced in JDK 1.0) that implements a synchronized resizable array as part of the List interface. Every method in Vector is synchronized, making it thread-safe but slower than non-synchronized alternatives. ArrayList is the unsynchronized modern alternative. Hashtable is synchronized but implements Map, not List. HashMap is unsynchronized and also implements Map.
To answer this question, you need to understand the concept of synchronization and the resizable-array implementation of the List interface.
The synchronized resizable-array implementation of the List interface is known as a Vector.
Let's go through each option to understand why it is correct or incorrect:
Option A) Vector - This option is correct because a Vector is a synchronized resizable-array implementation of the List interface. It provides thread-safe operations, meaning that multiple threads can access and modify the Vector object without causing data corruption.
Option B) ArrayList - This option is incorrect because although ArrayList is a resizable-array implementation of the List interface, it is not synchronized. It does not provide inherent thread-safety, so if multiple threads access and modify the ArrayList simultaneously, it can lead to data corruption.
Option C) Hashtable - This option is incorrect because Hashtable is not a resizable-array implementation of the List interface. It is an implementation of the Map interface and provides key-value pairs, not a sequence of elements like the List interface.
Option D) HashMap - This option is incorrect because HashMap is also not a resizable-array implementation of the List interface. It is also an implementation of the Map interface, providing key-value pairs, not a sequence of elements like the List interface.
The correct answer is A) Vector. This option is correct because Vector is the synchronized resizable-array implementation of the List interface. It provides thread-safe operations, making it suitable for multi-threaded environments.