Java: remove a range of indices from a list -


consider linked list of strings got somewhere

linkedlist<string> names = getnames(); 

now, want remove first k elements list. currently, i'll way:

for (int = 0 ; < k ; i++) {     names.removefirst(); } 

is there way more efficiently , instead call like:

names.removerange(0, k); 

note prefer not construct whole new list using sublist(), small k values, popping k times more efficient constructing new list

maybe :

names.sublist(0, k).clear(); 

this more efficient doesn't release memory according sublist it's view:

names.sublist(k, names.size()); 

Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

arrays - Algorithm to find ideal starting spot in a circle -