If I have a variable
LinkedList list
and repeatedly do the following to extract the tail of ‘list’
// Some operation that adds elements to 'list'
// max_size = some constant
list = (LinkedList) list.subList(list.size()-max_size, list.size());
do I end up with a lot of references to the ‘previous’ list?
So basically what I’m trying to do here is to remove an initial segment of the list.
Is there a better way to remove an initial segment of a LinkedList? I think the data structure of LinkedList should allow linear time (linear in the size of the initial segment to be removed) operation.
That code will simply fail – the returned sublist is not a
LinkedList<T>. Sample program:Output:
It sounds like you should just be calling
removeFirstas many times as you need to: