Tag: 循环列表

圆形ArrayList(扩展ArrayList)

所以我的程序需要一种圆形ArrayList。 关于它的只有圆形的东西必须是get(int index)方法,这是原始的: /** * Returns the element at the specified position in this list. * * @param index index of the element to return * @return the element at the specified position in this list * @throws IndexOutOfBoundsException {@inheritDoc} */ public E get(int index) { rangeCheck(index); return elementData(index); } 如果index为-1,则应获取索引为ArrayList.size() – 1的元素,如果index为ArrayList.size(),则应获取索引为0的元素。 我想到的最简单的实现方法就是简单地从java.util包中扩展ArrayList,然后重写get(int index),这样它就不会为上面的两个索引抛出IndexOutOfBoundsException,而是将它们改为我想要的。 […]