Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

ExtendedStringTokenizer


The ExtendedStringTokenizer class allows to iterate through a String and keep the empty token (which the StringTokenizer class don't do.

if ExtendedStringTokenizer.isKeepingEmptyTokens() return true, the behavior of the class is the behavior of the StringTokenizer class.

Configuration

The ExtendedStringTokenizer.keepEmptyTokens(boolean) method set if empty tokens should be returned by the ExtendedStringTokenizer.nextToken() or ExtendedStringTokenizer.nextElement() methods, and used by the ExtendedStringTokenizer.countTokens() method.

The ExtendedStringTokenizer.keepEmptyTokens(boolean) method will not change anything if the tokenizer has already been used by either the nextToken(), nextElement(), or countTokens() methods.

Example

Example with not returning delimiters:
   ExtendedStringTokenizer tok = new ExtendedStringTokenizer(",TheString,,", ",", false);
   tok.keepEmptyTokens(true); 
   String tk = tok.nextToken(); // return ""
   String tk = tok.nextToken(); // return "TheString"
   aString tk = tok.nextToken(); // return ""
   String tk = tok.nextToken(); // return ""
   boolean hasMore = tok.hasMoreTokens(); // return false;
Example with returning delimiters:
   ExtendedStringTokenizer tok = new ExtendedStringTokenizer(",TheString,,", ",", true);
   tok.keepEmptyTokens(true);
   String tk = tok.nextToken(); // return ""
   String tk = tok.nextToken(); // return ","     
   String tk = tok.nextToken(); // return "TheString"
   String tk = tok.nextToken(); // return ","           
   String tk = tok.nextToken(); // return ""
   String tk = tok.nextToken(); // return ","             
   String tk = tok.nextToken(); // return ""
   boolean hasMore = tok.hasMoreTokens()); // return false;

Categories: Packages | Util

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences