Strings [was Re: Sponsoring getting 5015163 "(str) String merge/join that is the inverse of String.split()" into JDK 7]

Kevin Bourrillion kevinb at google.com
Sun Nov 8 23:04:01 UTC 2009


On Mon, Oct 26, 2009 at 1:38 PM, Stephen Colebourne <scolebourne at joda.org>wrote:

Unfortunately, the null-handling behaviour of the static method is
> considered a feature to many


That is unfortunate.  <evil grin>  Luckily any new JDK methods would not
have to carry forward the null-tolerant approach. :-)


By the way, one advantage of a Strings class is that it could contain a new
> implementation of split - one that doesn't use regex and isn't as
> complex/useless as the current one on String.
>

Different splitting use cases want to specify the delimiter as any of a
regex, a literal String, a literal char, or what we (Guava) call a
"CharMatcher".  One way to support all these is to just support regex, as
any of the rest of these can be coerced into a regex; this is what
String.split() does.  Another way is to just outright support them all, as
Guava's Splitter does:

http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/base/Splitter.html

It also supports splitting into fixed-width segments, which -- well, I guess
that can be coerced into a regex too, just a really frickin' weird one.
Splitter has a few other optional behaviors that users depend on.  The point
of all this is that doing splitting well is going to take more than just a
few static methods in a utility class.  By and large, we've found this to be
the case with nearly everything (but not everything) we first thought of as
a StringUtil method.


-- 
Kevin Bourrillion @ Google
internal:  http://go/javalibraries
external: guava-libraries.googlecode.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/core-libs-dev/attachments/20091108/24ae930e/attachment.html>


More information about the core-libs-dev mailing list