Differentiate between an Array List and a Vector.
| ArrayList | Vector |
| An ArrayList is not synchronized. | A vector is synchronized. |
| An ArrayList is fast. | A vector is slow as it is thread-safe. |
| If an element is inserted into an ArrayList, it increases its array size by 50 percent. | A vector defaults to doubling the size of its array. |
| An ArrayList does not define the increment size. | A vector defines the increment size. |
| An ArrayList can only use Iterator for traversing. | Except for hash table, a vector is the only other class that uses both Enumeration and Iterator. |
Mention the difference between Iterator and Enumeration.
| Iterator | Enumeration |
| Iterator is an interface found in the java.util package. | Enumeration is an object that generates elements one at a time. |
Uses three methods to interface:
| Uses two methods:
|
| Iterators allow removing elements from the given collection during the iteration with well-defined semantics. | It is used for passing through a collection, usually of unknown size. |
| Iterator method names have been improved. | The traversing of elements can only be done once per creation. |
Explain the difference between the inner class and the subclass.
| Inner Class | Subclass |
| An inner class is a class that is nested within another class. | A subclass is a class that inherits from another class called the superclass. |
| It provides the access rights for the class which is nesting it and that can access all variables and methods defined in the outer class. | It provides access to all public and protected methods and fields of its superclass. |
No comments:
Post a Comment