Java : RandomAccess with Examples
RandomAccess (Java SE 21 & JDK 21) with Examples.
You will find code examples on most RandomAccess methods.
Summary
Marker interface used by List implementations to indicate that they support fast (generally constant time) random access. 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.
final var arrayList = new ArrayList<String>();
System.out.println(arrayList instanceof RandomAccess); // true
final var linkedList = new LinkedList<String>();
System.out.println(linkedList instanceof RandomAccess); // false
Related posts
- API Examples