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.
Asked
Active
Viewed 3.6k times
15

nikhil
- 8,925
- 21
- 62
- 102
2 Answers
30
Use the constructor with two arguments, where the second is the delimiters.
StringTokenizer tokenizer = new StringTokenizer(yourString, "!*^/");

MByD
- 135,866
- 28
- 264
- 277
-
3He's asking of multiple delimiters. – Mob Feb 25 '12 at 18:44
-
2@Mob yup this is the way.. in here all the 4 !,*,/,^ are defined as !*^/ – tk_ Dec 15 '14 at 10:43
-
3Can you make a delimiter that has more than one character e.g., AVG? – Cronas De Se May 19 '16 at 10:18
4
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.

JProgrammer
- 1,135
- 1
- 10
- 27