Split text in JME and assign values ​​in an array

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

String[] myToken;
StringTokenizer tokenObject;
tokenObject = new StringTokenizer("one-two-three","-");
myToken= tokenObject.nextToken();
+3
source share
1 answer

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

Try the following:

StringTokenizer tokenizer = new StringTokenizer("one-two-three", "-");
while (tokenizer.hasMoreTokens()) {
    String token = tokenizer.nextToken();
    // Do something with variable "token"
}
+6
source

All Articles