Monday, May 10, 2010

Collection Interview Question

Difference between Hashmap and Hash table
1. Hashtable is sysnchronized but hash map is not thread safe.
2. Hashtable is not allow the null value and null key but hashmap is allow one null key and multiple null values.
3. HashMap retrieval is not in order (random). HashTable provide ordered retrieval.
4. In HashTable you can change the iteration but in the case of HashMap you can change the iteration but you will get a sjava.util.ConcurrentModificationException.

Difference between Vector and ArrayList? What is the Vector class?
Vector is synchronized whereas ArrayList is not. The Vector class provides the capability to implement a growable array of objects.
ArrayList and Vector class both implement the List interface. Both classes are implemented using dynamically resizable arrays, providing fast random access and fast traversal.
In vector the data is retrieved using the elementAt() method while in ArrayList, it is done using the get() method. ArrayList has no default size while vector has a default size of 10.

What is difference between array & arraylist?
An ArrayList is resizable, where as, an array is not. ArrayList is a part of the Collection Framework. We can store any type of objects, and we can deal with only objects. It is growable. Array is collection of similar data items. We can have array of primitives or objects. It is of fixed size. We can have multi dimensional arrays.
Array: can store primitive ArrayList: Stores object only
Array: fix size ArrayList: resizable
Array: can have multi dimensional
Array: lang ArrayList: Collection framework

No comments:

Post a Comment