https://sites.google.com/site/furodet/tips-for-java-rookies/first-steps-with-java-iterator
https://gist.github.com/heslei/1983172
http://www.keithschwarz.com/interesting/code/?dir=fibonacci-iterator
public class Fibonacci implements Iterable<Integer> {
private class FibonacciIterator implements Iterator<Integer> {
/** Last and last but one elements. */
private int b0 = 0, b1 = 1;
@Override
public boolean hasNext() {
return true;
}
@Override
public Integer next() {
int value = b0 + b1;
b0 = b1;
b1 = value;
return value;
}
@Override
public void remove() {}
}
@Override
public Iterator<Integer> iterator() {
return new FibonacciIterator();
}
}
https://gist.github.com/heslei/1983172
http://www.keithschwarz.com/interesting/code/?dir=fibonacci-iterator