@Override
  public ObjectListIterator<K> listIterator(final int index) {
    ensureIndex(index);
    return new AbstractObjectListIterator<K>() {
      int pos = index, last = -1;

      @Override
      public boolean hasNext() {
        return pos < size;
      }

      @Override
      public boolean hasPrevious() {
        return pos > 0;
      }

      @Override
      public K next() {
        if (!hasNext()) {
          throw new NoSuchElementException();
        }
        return a[last = pos++];
      }

      @Override
      public K previous() {
        if (!hasPrevious()) {
          throw new NoSuchElementException();
        }
        return a[last = --pos];
      }

      @Override
      public int nextIndex() {
        return pos;
      }

      @Override
      public int previousIndex() {
        return pos - 1;
      }

      @Override
      public void add(K k) {
        if (last == -1) {
          throw new IllegalStateException();
        }
        IdentityArrayList.this.add(pos++, k);
        last = -1;
      }

      @Override
      public void set(K k) {
        if (last == -1) {
          throw new IllegalStateException();
        }
        IdentityArrayList.this.set(last, k);
      }

      @Override
      public void remove() {
        if (last == -1) {
          throw new IllegalStateException();
        }
        IdentityArrayList.this.remove(last);
        /*
         * If the last operation was a next(), we are removing an element *before* us, and we must
         * decrease pos correspondingly.
         */
        if (last < pos) {
          pos--;
        }
        last = -1;
      }
    };
  }
Adds elements to this type-specific list using optimized system calls.

@param index the index at which to add elements.
@param a the array containing the elements.
@param offset the offset of the first element to add.
@param length the number of elements to add.
geode-core/src/main/java/org/apache/geode/internal/cache/IdentityArrayList.java