ma.vi.base.collections.CharIterator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.vikmad.base Show documentation
Show all versions of com.vikmad.base Show documentation
Base algos, data structures and utilities
The newest version!
package ma.vi.base.collections;
import java.util.Iterator;
/**
* An iterator over characters in character sequence.
*
* @author Vikash Madhow ([email protected])
*/
public class CharIterator implements Iterator {
/**
* Creates an iterator that will iterate over the provided items
*/
public CharIterator(CharSequence sequence) {
this.sequence = sequence;
}
@Override
public synchronized boolean hasNext() {
return position < sequence.length();
}
@Override
public synchronized Character next() {
return sequence.charAt(position++);
}
/**
* Character sequence to iterate over
*/
private final CharSequence sequence;
/**
* Current position of iterator which is the position of the item that
* will be returned by {@link #next()}.
*/
private int position = 0;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy