I have a class that stores String-type data that can be compared based on the length of the string ( compareTo() ), iterated by chars ( iterator() ).
I have implemented compareTo
method but I don't know how to implement the iterator()
public class ExtendedString implements Comparable<ExtendedString>,Iterable<Character>{
private String str;
public ExtendedString(String str) {
this.str = str;
}
public int compareTo(ExtendedString estr) {...}
public Iterator<Character> iterator() {
???
}
}
My question is how should I implement iterator()
?