I want the indices of the elements in the Java list to be fixed.
Code example:
import java.util.ArrayList;
public class Test {
public static void main(String[] args) {
ArrayList<Double> a = new ArrayList<Double>();
a.add(12.3);
a.add(15.3);
a.add(17.3);
a.remove(1);
System.out.println(a.get(1));
}
}
This will exit 17.3. The problem is that it 17.3was at index 2, and now it is at index 1!
Is there a way to keep indices of other elements when deleting an element? Or is there another class more suitable for this purpose?
Note. I do not need a fixed size collection.
source
share