IntelliJ Java IDE
The moose likes Java in General and the fly likes RandomAccess Interface 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
Marshal

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

Android appsImageJ pluginsJava web charts
 
 
subject: RandomAccess Interface
 
Threads others viewed
Null Interface
Sun's New Sample 1.4 Exam
How does a class gets that functionality from marker interface?
marker interfaces
Purpose of Marker Interface
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture