GD_Java GD_Java - 1 month ago 4
Java Question

Why does ArrayList implement RandomAccess Interface?

ArrayList
implements
RandomAccess
interface.
RandomAccess
interface has no methods. When I checked
LinkedList
it does not implement
RandomAccess
interface.

So in case of
ArrayList
, what is the point of implementing it?

Answer

Interfaces with no methods are called marker interfaces in Java.

As per the JavaDoc of RandomAccess:

Marker interface used by List implementations to indicate
that they support fast (generally constant time) random access.

For more information check the two JavaDoc pages.

http://docs.oracle.com/javase/6/docs/api/java/util/RandomAccess.html

http://docs.oracle.com/javase/6/docs/api/java/util/ArrayList.html