You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static <E> E findKthRecursive(LinkedList<E> list, Integer k){
if(list.size()==0 || list==null){
throw new NoSuchElementException("No elements in this list");
}
if(k >= list.size()){
throw new IndexOutOfBoundsException("Index k is out of bounds");
}
if(k==0) return list.pollFirst();
list.pollFirst();
return findKthRecursive(list,k - 1);
}
because the method sublist will create a SublistObject which has a field references the original list,if the original is very large,you will have a Memory leak,because the original list will never GC by JVM until your sublist without use.
PS:my English is very bad,so if anywhere offend/confuse you , or I say somthing wrong ,thanks for your feedback
The text was updated successfully, but these errors were encountered:
I think you'd better use my codes below:
because the method sublist will create a SublistObject which has a field references the original list,if the original is very large,you will have a Memory leak,because the original list will never GC by JVM until your sublist without use.
PS:my English is very bad,so if anywhere offend/confuse you , or I say somthing wrong ,thanks for your feedback
The text was updated successfully, but these errors were encountered: