If you want that behaviour:
List<T> snake = new ArrayList<>(){
@Override
public T get(int i) {
return super.get((i + size()) % size());
}
};
This will work for any value of i.
More Related Contents:
- Unexpected output when creating a List of Lists in Java
- Getting Arraylist IndexOutOfBoundsException
- Create ArrayList from array
- Why do I get an UnsupportedOperationException when trying to remove an element from a List?
- How to randomize two ArrayLists in the same fashion?
- ConcurrentModificationException when adding inside a foreach loop in ArrayList [duplicate]
- What are the differences between ArrayList and Vector?
- How much data can a List can hold at the maximum?
- How do I find out what type each object is in a ArrayList?
- From Arraylist to Array
- Stream Filter of 1 list based on another list
- Trouble with Gson serializing an ArrayList of POJO’s
- Finding duplicate values in arraylist
- Creating an Arraylist of Objects
- Empty an ArrayList or just create a new one and let the old one be garbage collected? [duplicate]
- Simple way to compare 2 ArrayLists
- Memory overhead of Java HashMap compared to ArrayList
- Hash Set and Array List performances
- Scanner skipping every second line from file [duplicate]
- ArrayList: how does the size increase?
- Add an object to an ArrayList and modify it later
- Check if an ArrayList contains every element from another ArrayList
- Adding to an ArrayList Java
- Can not deserialize instance of java.util.ArrayList out of VALUE_STRING
- Merging two arrayLists into a new arrayList, with no duplicates and in order, in Java
- Time Complexity for Java ArrayList
- Finding out if a list of Objects contains something with a specified field value?
- Java ArrayList how to add elements at the beginning
- Vector vs Collections.synchronizedList(ArrayList)
- Remove object from ArrayList with some Object property