public class SubstringIterator extends Objectimplements Iterator <String >
java.lang.String. For example: the string "abcde" will yield: "abcde", "abcd", "bcde", "abc", "bcd", "cde", "ab", "bc", "cd", "de", "a", "b", "c", "d", "e".
There is also an option to return only unique substrings. If this option is active and the original string is "apple", then "p" will only be returned once instead of twice.
| Constructor and Description |
|---|
SubstringIterator(String
Create a
SubstringIterator that returns every possible substring of the original text.
|
SubstringIterator(String
Create a
SubstringIterator.
|
| Modifier and Type | Method and Description |
|---|---|
int |
getCurrentLength()
Returns the length of the substring to be returned by
next().
|
boolean |
hasNext()
|
String |
next()
|
void |
remove()
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEachRemainingpublic SubstringIterator(Stringtext)
SubstringIterator that returns every possible substring of the original text.
text - the text to break into substrings.
public SubstringIterator(Stringtext, boolean onlyUniqueSubstrings)
SubstringIterator.
text - the text to break into substrings.
onlyUniqueSubstrings - if this is true then this iterator will never return the same substring twice. For example substrings of "maintain" may include two copies of "ain" if this boolean is false.
public boolean hasNext()
public int getCurrentLength()
next(). This value decreases from the original string length to 1 as this iterator progresses.
public Stringnext()
public void remove()