3

I'm trying to create an array in j2me with split text. I'm trying to use the StringTokenizer class from ostermiller.org. However I can't figure out how to assign the tokens into an array. What could be wrong with this code?

String[] myToken;
StringTokenizer tokenObject;
tokenObject = new StringTokenizer("one-two-three","-");
myToken= tokenObject.nextToken();
gnat
  • 6,213
  • 108
  • 53
  • 73
sammyukavi
  • 1,501
  • 2
  • 23
  • 51

1 Answers1

6

You have to use a loop that checks if there are more tokens and in the loop gets the next token.

Try this:

StringTokenizer tokenizer = new StringTokenizer("one-two-three", "-");
while (tokenizer.hasMoreTokens()) {
    String token = tokenizer.nextToken();
    // Do something with variable "token"
}
Bohemian
  • 412,405
  • 93
  • 575
  • 722