// Class ArrayIntList can be used to store a list of integers. public class ArrayIntList { private int[] elementData; private int size; // constructs a list with a capacity of 100 public ArrayIntList() { elementData = new int[100]; size = 0; } // returns a comma-separated, bracketed version of the list public String toString() { if (size == 0) { return "[]"; } else { String result = "[" + elementData[0]; for (int i = 1; i < size; i++) { result += ", " + elementData[i]; } result += "]"; return result; } } // returns the index of the first occurence of value, -1 if not found public int indexOf(int value) { for (int i = 0; i < size; i++) { if (elementData[i] == value) { return i; } } return -1; } // appends the given value to the end of the list public void add(int value) { elementData[size] = value; size++; } // adds the value at the given index public void add(int index, int value) { for (int i = size; i > index; i--) { elementData[i] = elementData[i - 1]; } elementData[index] = value; size++; } // removes the value at the given index public void remove(int index) { for (int i = index; i < size - 1; i++) { elementData[i] = elementData[i + 1]; } size--; } }