public class LoopArray { float[] arr; int startIndex, len; public LoopArray(int size) { arr = initArray(size); } private float[] initArray(int size){ return new float[size]; } public int getIndex() { return startIndex; } public float[] getArray() { return arr; } public int getLength() { return len; } public void put(float value) { arr[(startIndex + len) % arr.length] = value; if (len < arr.length) len++; else { startIndex = (startIndex + 1) % arr.length; } } public float[] get() { float[] data = initArray(len); for (int i = 0; i < data.length; i++) { data[i] = arr[(i + startIndex) % arr.length]; } return data; } }