Class KmgStringTokenizer
- java.lang.Object
-
- KmgStringTokenizer
-
- All Implemented Interfaces:
Enumeration
,Iterator
public class KmgStringTokenizer extends Object implements Enumeration, Iterator
Variant ofjava.util.
StringTokenizer
with different handling of consecutive delimiters. For detailssee
.
-
-
Constructor Summary
Constructors Constructor Description KmgStringTokenizer(String text)
Shortcut ofKmgStringTokenizer
( text, "\t\n\r\f", " " )
.KmgStringTokenizer(String text, String delim1, String delim2)
Variant ofStringTokenizer
which supports two different types of delimiters, see Parametersdelim1
anddelim2
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
get(int i)
Returns the next token after skippingi
tokens.String
getRemaining()
Returns all remaining text without considering any delimiters.boolean
hasMoreElements()
boolean
hasNext()
ReturnshasMoreElements()
.static void
main(String[] args)
Test.Object
next()
Returns the next token ornull
, if no more tokens available.Object
nextElement()
Returns the next token ornull
, if no more tokens available.String
nextToken()
Returns the next token ornull
, if no more tokens available.String
nextToken(String delim1, String delim2)
Returns the next token after changing the delimiters to the given values.KmgStringTokenizer
reset()
Resets the internal parse position (The delimiter set remains the same).KmgStringTokenizer
setDelimiters(String delim1, String delim2)
Sets the delimiters to the given values (The parse position remains the same,""
ignores the delimiter,null
does not change the delimiter).String[]
split()
Returns an array containing all (remaining) tokens.String[]
split(int n)
Returns an array containingn
(remaining) tokens.static String[]
test(Enumeration st)
Returns an array containing the String representation of the elements ofst
.-
Methods inherited from interface java.util.Enumeration
asIterator
-
Methods inherited from interface java.util.Iterator
forEachRemaining, remove
-
-
-
-
Constructor Detail
-
KmgStringTokenizer
public KmgStringTokenizer(String text, String delim1, String delim2)
Variant ofStringTokenizer
which supports two different types of delimiters, see Parametersdelim1
anddelim2
.
Examples:KmgStringTokenizer( "abc\t\txyz", "", "\t" ) returns "abc", "xyz" // same result as
StringTokenizer
KmgStringTokenizer( "abc\t\txyz", "\t", "" ) returns "abc", "", "xyz" KmgStringTokenizer( " abc \t \t xyz ", "\t", " " ) returns "abc", "", "xyz" KmgStringTokenizer( " \t abc : xyz || ", "|\t", ": " ) returns "", "abc", "xyz", "", ""KmgStringTokenizer( text, "", delim2 )
is equivalent tojava.util.StringTokenizer( text, delim2 )
- Parameters:
text
- string containing tokens separated by delimitersdelim1
- consecutive delimiters of this type count separately andnextToken()
returns "" (empty string)delim2
- delimiters of this type adjacent to another delimiter are ignored ⇒ consecutive delimiters count as one single delimiter
-
KmgStringTokenizer
public KmgStringTokenizer(String text)
Shortcut ofKmgStringTokenizer
( text, "\t\n\r\f", " " )
.
-
-
Method Detail
-
reset
public KmgStringTokenizer reset()
Resets the internal parse position (The delimiter set remains the same).- Returns:
- this
-
setDelimiters
public KmgStringTokenizer setDelimiters(String delim1, String delim2)
Sets the delimiters to the given values (The parse position remains the same,""
ignores the delimiter,null
does not change the delimiter).- Returns:
- this
-
hasNext
public boolean hasNext()
ReturnshasMoreElements()
.
-
hasMoreElements
public boolean hasMoreElements()
- Specified by:
hasMoreElements
in interfaceEnumeration
-
next
public Object next()
Returns the next token ornull
, if no more tokens available.
-
nextElement
public Object nextElement()
Returns the next token ornull
, if no more tokens available.- Specified by:
nextElement
in interfaceEnumeration
-
nextToken
public String nextToken()
Returns the next token ornull
, if no more tokens available.
-
nextToken
public String nextToken(String delim1, String delim2)
Returns the next token after changing the delimiters to the given values. The new delimiter set remains the default after this call.
-
get
public String get(int i)
Returns the next token after skippingi
tokens.
-
split
public String[] split()
Returns an array containing all (remaining) tokens.- See Also:
String.split(java.lang.String, int)
-
split
public String[] split(int n)
Returns an array containingn
(remaining) tokens. Iftext
does not contain sufficient tokens, the missing array elements are null.
-
getRemaining
public String getRemaining()
Returns all remaining text without considering any delimiters.
-
test
public static String[] test(Enumeration st)
Returns an array containing the String representation of the elements ofst
.
-
main
public static void main(String[] args)
Test.
-
-