I am having a hard time with using the Iteration class. I don't know how to effectively use the "next()" method, it confuses me. When I search for the last product in the list nothing prints out because at that time it is looking at the next item in the list. Do I use a variable that I subtract 1 from? Here is my code, any help would be awesome.
public Product findProduct(int id) { Iterator<Product> p = stock.iterator(); boolean looking = true; while(looking && p.hasNext()) { int searchID = p.next().getID(); if (p.hasNext() && id == searchID) { Product foundProduct = p.next(); looking = false; return foundProduct; } } return null; }