Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split text in JME and assign values in an array

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();
like image 607
sammyukavi Avatar asked Mar 08 '26 19:03

sammyukavi


1 Answers

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"
}
like image 143
Bohemian Avatar answered Mar 11 '26 08:03

Bohemian