I use HashSet methods for add(); remove(); clear(); iterator();. So far, everything has worked like a charm. However, now I need to fulfill another requirement.
I would like to be able to start the iteration from a specific index. For example, I would like the following two programs to have the same output.
Program 1
Iterator it=map.iterator();
for(int i=0;i<100;i++)
{
it.next();
}
while (it.hasNext())
{
doSomethingWith(it.next());
}
Program 2
Iterator it=map.iterator(100);
while (it.hasNext())
{
doSomethingWith(it.next());
}
The reason I don't want to use program 1 is because it creates unnecessary overhead. From my research, I could not find a practical way to create an iterator with an initial index.
So my question is, what would be a good way to achieve my goal while minimizing overhead?
Thank.
source
share