In Java, I would like to use the clear() method on a list so that the items cleared from the sublist are also removed from the original list. Is there a way to create a sublist where the indices are non continuous, so that I can still use the clear() method to remove the items from the original list?
In Java, I would like to use the clear() method on a list so
Share
None of the default
Listimplementations support this behavior. You could overrideArrayListand support aclear(),remove(), etc.. that turns around and callsremove()on the parent list.Something like the following example code. But to keep it properly in sync with the parent is going to take a lot of work. If you can limit the number of calls that you need to support then it would be a lot easier of course.