aspose file tools*
The moose likes Java in General and the fly likes RandomAccess Interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "RandomAccess Interface" Watch "RandomAccess Interface" New topic
Author

RandomAccess Interface

Ruchika Kapoor
Greenhorn

Joined: Oct 03, 2004
Posts: 22
How does RandomAccess interface helps in faster access of Vector/ArrayList. This is just a marker interface that how does implementing it improvess access time.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
The key is in the code that works with objects/classes that implement this interface (this is true for all marker interfaces, by the way). You'll find these if you search through the source files of the Java class libraries looking for "instanceof RandomAccess" (which is how you check an object for whether it implements this interface).

I'll spare you the suspense and point out that it's used mostly in the java.util.Collections class. Have look at its source code; wherever you see "instanceof RandomAccess", it'll invariably be part of an "if" statement that decides which of two algorithms to use. And the one being used if the instanceof check is successful is generally (much) faster than the other one.
[ July 24, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RandomAccess Interface
 
Similar Threads
Null Interface
Purpose of Marker Interface
How does a class gets that functionality from marker interface?
Sun's New Sample 1.4 Exam
marker interfaces