I think the answer to this is no, but I'm asking just to be sure...
Python has "generators" which are functions that remember where it left off so that every time you call the generator's "next()" function, you get the next object until you reach the end when it throws an exception. It's really handy for iterating over stuff without the overhead of having to keep track of where you are yourself. Is there something similar in Java?
What I'm trying to do is read from a database and iterate over the results of a query without having to return the actual resultSet itself. I want to keep the resultSet in my class and just keep returning the next row when it's requested. I'm assuming, without generators, that I can just put chunks of the result in a list and keep track of where I am and just keep refilling my list until I reach the end...but I'm lazy .
Also take care of what to return. Will it be a String, an Object, a Map<String,String>, a Map<String,Object>, or perhaps even instances of a class that will hold all the data.
There is one issue with creating an Iterator over a ResultSet - ResultSet's next() will return false when you're done, whereas Iterator's next() will throw an exception. It has the hasNext() method for querying whether or not to go on. ResultSet's next is a bit like a combination of Iterator's hasNext() and next() combined into one.