Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need for RandomAccess interface

 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the significance of the RandomAccess interface for list implementations?
By marking my list implementation using this interface will i get any support from the JVM interms of checks?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does just what the API says it does - it allows other code to decide (using instanceof) whether get(int) is an efficient method to use on this list, or whether it's better to use an Iterator. This allows code such as the Collections class to perform better, as it can chose an algorithm suited to the performance characteristics of the List. Check out the source code of java.util.Collections (in src.zip) to see examples of this.
By marking my list implementation using this interface will i get any support from the JVM interms of checks?
Assuming your list implementation really is a random-access list (e.g. not a linked list), you get better performance from some methods in Collections, and possibly other classes. That's it.
[ May 20, 2002: Message edited by: Jim Yingst ]
 
william kane
Ranch Hand
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanx jim
i'll look into the collections class and see how ramdom access is been used
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic