Powered byFreelance Jobs
The moose likes Java in General and the fly likes RandomAccess Interface The Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply 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
Sheriff

Joined: Mar 22, 2005
Posts: 28826
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 ]

cewolf - Java web chartsMy Android appsImageJ Plugins
 
YouTrack 2.0
 
subject: RandomAccess Interface
 
Java Business RIA redefined!

.