StringTokenizer in GWT

2,686 views
Skip to first unread message

Anti

unread,
Jul 31, 2008, 7:12:20 PM7/31/08
to Google Web Toolkit
Hello Everybody,

StringTokenizer is very useful but seems I cannot use it in GWT, these
lines of code:

StringTokenizer stringTokenizer = new
StringTokenizer(sender.getFileName(), "\\");
while(stringTokenizer.hasMoreTokens()){
shortName = stringTokenizer.nextToken();
}

throw...:

Line 72: No source code is available for type
java.util.StringTokenizer; did you forget to inherit a required
module?

What can I do?

Thanks.

Kroc

unread,
Jul 31, 2008, 10:48:17 PM7/31/08
to Google Web Toolkit
I don't know for this error.

but from javadoc API you can read this:
StringTokenizer is a legacy class that is retained for compatibility
reasons although its use is discouraged in new code. It is recommended
that anyone seeking this functionality use the split method of String
or the java.util.regex package instead.

So, try other method.
I'm sucessfully using split method.

Vincent

olivier nouguier

unread,
Aug 1, 2008, 5:26:12 AM8/1/08
to Google-We...@googlegroups.com
Hi,

 More generally, look at:
http://code.google.com/webtoolkit/documentation/jre.html to find GWT emulation of JRE classes.
In this case String.split is indeed available.

Regards.
--
"Quand le dernier arbre sera abattu, la dernière rivière asséchée, le dernier poisson péché, l'homme va s'apercevoir que l'argent n'est pas comestible"
- proverbe indien Cri

Boštjan Pajntar

unread,
Jun 24, 2014, 9:02:09 AM6/24/14
to google-we...@googlegroups.com, Google-We...@googlegroups.com, vincent....@gmail.com
StringTokenizer is not depracatd though. There is also a good reason for this, as it is quite faster than the split method.

Check a comparison


Dne petek, 01. avgust 2008 04:48:17 UTC+2 je oseba Kroc napisala:

Thomas Broyer

unread,
Jun 24, 2014, 6:29:50 PM6/24/14
to google-we...@googlegroups.com, Google-We...@googlegroups.com, vincent....@gmail.com
Keep in mind that performance in the JVM is not the same as performance in GWT once compiled to JS.

In GWT, if you don't need regexp and only have one separator char, you'd probably better use indexOf and substring I guess.
If you need regexps, or have several separators, then using com.google.gwt.regexp (in the same way as indexOf) would work and should be fast.
…or you could use Guava's Splitter.
Reply all
Reply to author
Forward
0 new messages