InterviewSolution
| 1. |
What is the purpose of RandomAccess Interface? Name a collection type which implements this interface. |
|
Answer» RandomAccess, like the Serializable and Cloneable interfaces, is a marker interface. There are no methods defined in any of these marker interfaces. RATHER, they designate a class as having a SPECIFIC capability. The RandomAccess interface indicates whether or not a given java.util.List implementation supports RANDOM access. This interface seeks to define a vague concept: what does it mean to be fast? A simple guide is provided in the documentation: The List has fast random access if repeated access using the List.get( ) method is FASTER than repeated access using the ITERATOR.next( ) method. Repeated access using List.get( ): Object obj;for (int i=0, n=list.size( ); i < n; i++) obj = list.get(i);Repeated access using Iterator.next( ): Object obj;for (Iterator itr=list.iterator( ); itr.hasNext( ); ) obj = itr.next( ); |
|