File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes need for RandomAccess interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "need for RandomAccess interface" Watch "need for RandomAccess interface" New topic
Author

need for RandomAccess interface

william kane
Ranch Hand

Joined: Nov 21, 2000
Posts: 260
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?


Help me!Help you!!!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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 ]

"I'm not back." - Bill Harding, Twister
william kane
Ranch Hand

Joined: Nov 21, 2000
Posts: 260
hey thanx jim
i'll look into the collections class and see how ramdom access is been used
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need for RandomAccess interface