Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codename One - String split

I have a method that splits a string and continues with its logic after.

Now this method works in say a console or fx but using Codename One I get

error: cannot find symbol
for (String word : comment.split("\\s+"))
      symbol:   method split(String)
      location: variable comment of type String
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.

Now I know that Codename One is not the FULL JSK but more a restricted subset but I haven't found an alternative to splitting a string.

Should I create my own method or is there a way around to use another function?

like image 285
Ranked Bronze Avatar asked May 08 '26 22:05

Ranked Bronze


1 Answers

For anyone looking to make their life easier here is a convenience method

public String[] split(String str)
{
    ArrayList<String> splitArray = new ArrayList<>();
    StringTokenizer arr = new StringTokenizer(str, ",");//split by commas
    while(arr.hasMoreTokens())
        splitArray.add(arr.nextToken());
    return splitArray.toArray(new String[splitArray.size()]);
}
like image 176
JAnton Avatar answered May 10 '26 13:05

JAnton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!