• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

RandomAccess Interface  RSS feed

 
Greenhorn
Posts: 22
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 42974
76
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!