接口作用
實作該接口,就說明支援随機通路方式周遊
例子
public static void main(String[] args) {
ArrayList<String> list = new ArrayList<>();
if (list instanceof RandomAccess) {
//随機通路
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
} else {
//疊代器通路
Iterator<String> iterator = list.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
}