public class RETokenizer extends Object implements Iterator<String>
Pattern p=new Pattern("\\s+"); //any number of space characters
String text="blah blah blah";
//by factory method
RETokenizer tok1=p.tokenizer(text);
//or by constructor
RETokenizer tok2=new RETokenizer(p,text);
Now the one way is to use the tokenizer as a token enumeration/iterator:while(tok1.hasMore()) System.out.println(tok1.nextToken());and another way is to split it into a String array:
String[] arr=tok2.split();
for(int i=0;i<tok2.length;i++) System.out.println(arr[i]);Pattern.tokenizer(java.lang.String)| Constructor and Description |
|---|
RETokenizer(Pattern pattern,
char[] chars,
int off,
int len) |
RETokenizer(Pattern pattern,
Reader r,
int len) |
RETokenizer(Pattern pattern,
String text) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
hasNext() |
boolean |
isEmptyEnabled() |
String |
next() |
void |
remove()
Removes from the underlying collection the last element returned
by this iterator (optional operation).
|
void |
reset() |
void |
setEmptyEnabled(boolean b) |
String[] |
split() |
String |
toString() |
clone, finalize, getClass, notify, notifyAll, wait, wait, waitforEachRemainingpublic RETokenizer(Pattern pattern, String text)
public RETokenizer(Pattern pattern, char[] chars, int off, int len)
public RETokenizer(Pattern pattern, Reader r, int len) throws IOException
IOExceptionpublic void setEmptyEnabled(boolean b)
public boolean isEmptyEnabled()
public void reset()
public void remove()
next(). The behavior of an iterator
is unspecified if the underlying collection is modified while the
iteration is in progress in any way other than by calling this
method.remove in interface Iterator<String>UnsupportedOperationException - if the remove
operation is not supported by this iteratorIllegalStateException - if the next method has not
yet been called, or the remove method has already
been called after the last call to the next
methodCopyright © 2016. All rights reserved.