[Logo]

Register / Login

Java Forums » Java » Java in General
RandomAccess Interface
Post by: Ruchika Kapoor, Greenhorn
on Jul 24, 2008 03:51:00
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.

Post by: Ulf Dittmer, Rancher
on Jul 24, 2008 05:17:00
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 ]





All times above are in ranch (not your local) time.
The current ranch time is
Sep 05, 2015 03:18:51.

Search | Recent Topics | Flagged Topics | Zero Replies

Copyright © 1998-2015 Paul Wheaton

Jump to top of page
Or visit our non-mobile (full) site