package circularlist; import java.util.Objects; public class CircularList { private Object[] elements; public CircularList(Object... elements) { this.elements = elements; } /** get the element at index i % size(). */ public Object get(int i) { return elements[i % elements.length]; } /** return the first index of the object o in the circular list, -1 if the ** object is not present. Note that an element of the circular list may be ** null. */ public int indexOf(Object o) { for (int i = 0; i < elements.length; i++) { if (Objects.equals(elements[i], o)) return i; } return -1; } /** number of elements contained in the circular list. */ public int size() { return elements.length; } public static void main(String[] args){ CircularList cl = new CircularList(1, 2, 3); System.out.print(cl); } }