I apologize for the basic question but my newness to Java is causing me some frustration and I am unable to find an elegant way to do this from my searches.
I want to iterate through a linked list using a For construct but also have an numerical iterator so that I can break the loop after a certain number of iterations.
I have this LL that I am iterating through:
LinkedList<SearchResult> docSearch;
I tried doing it like this but then only the iterator part worked (the result was always stuck on the first entry for each iteration)
for (SearchResult result : docSearch) while (iter2 < 50) {
//do stuff
iter2 = iter2 + 1;
}
Any advice is appreciated
If you have to do that sort of checking, then I would just do it with an if in the block.