[Java] RandomAccess

RandomAccess is a marker interface. It doesn't define methods; instead, it identifies a class as having a particular capability.

According to the online document:

The primary purpose of this interface is to allow generic algorithms 
to alter their behavior to provide good performance when applied to 
either random or sequential access lists.


To be more specific, for typical instances of the class, this loop:

for (int i=0, n=list.size(); i < n; i++)
     list.get(i);


runs faster than this loop:

for (Iterator i=list.iterator(); i.hasNext(); )
     i.next();


The well-known implementing classes are:

ArrayList, Stack, Vector

你可能感兴趣的:(java,Access,performance)