I'd like to know how I can use multiple delimiters with StringTokenizer in java.
For example one of these !,*,/,^
will occur as a delimiter. Also there will only be one at a time.
StringTokenizer is a legacy class (i.e. there is a better replacement out there), but it's not deprecated.
Constructs a string tokenizer for the specified string. The tokenizer uses the default delimiter set, which is " \t\n\r\f" : the space character, the tab character, the newline character, the carriage-return character, and the form-feed character.
Constructors of the StringTokenizer Class It creates StringTokenizer with specified string and delimiter. It creates StringTokenizer with specified string, delimiter and returnValue. If return value is true, delimiter characters are considered to be tokens. If it is false, delimiter characters serve to separate tokens.
Use the constructor with two arguments, where the second is the delimiters.
StringTokenizer tokenizer = new StringTokenizer(yourString, "!*^/");
You can use String.split() method because it takes regex as a parameter. You can specify Regex such that it can split the string based upon one of these deliminators.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With