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
Post a Comment