15

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.

nikhil
  • 8,925
  • 21
  • 62
  • 102

2 Answers2

30

Use the constructor with two arguments, where the second is the delimiters.

StringTokenizer tokenizer = new StringTokenizer(yourString, "!*^/");
MByD
  • 135,866
  • 28
  • 264
  • 277
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