• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RandomAccess Interface

 
Greenhorn
Posts: 22
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 43081
77
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic