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();
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"
}
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