Use StringBuilder in java.util.Matcher

David Dabbs dmdabbs at gmail.com
Thu Jul 29 12:20:12 PDT 2010


Changing the signature to AbstractStringBuilder would make it compatible
with both.


abstract class: AbstractStringBuilder [javadoc | source]

java.lang.Object
   java.lang.AbstractStringBuilder

Direct Known Subclasses:
    StringBuilder, StringBuffer

          since: 1.5




Best,

David


-----Original Message-----
From: nio-dev-bounces at openjdk.java.net
[mailto:nio-dev-bounces at openjdk.java.net] On Behalf Of ibrahim CHAEHOI
Sent: Thursday, July 29, 2010 1:50 PM
To: nio-dev at openjdk.java.net
Subject: Use StringBuilder in java.util.Matcher

Hi all,

I'm not sure if it's the right mailing list to post this question,
if it's not the case please let me know what is the proper mailing
list to post this question.

I just would like to know if there is any reason why the
appendReplacement method in java.util.Matcher API is only using
StringBuffer.
Would it be possible to add 2 new methods appendReplacement and
appendTail which use a StringBuilder instead of a StringBuffer?

public Matcher appendReplacement(StringBuilder sb, String replacement);

public StringBuilder appendTail(StringBuilder sb, String replacement);

The StringBuilder was introduce in Java 5 as an optimized version of
the StringBuffer, when the synchronization is not necessary,
and I'm a bit surprised that the Matcher API doesn't provide a method
which use a StringBuilder.

Cheers,

No virus found in this incoming message.
Checked by AVG - www.avg.com 
Version: 9.0.851 / Virus Database: 271.1.1/3035 - Release Date: 07/29/10
01:34:00



More information about the jdk7-dev mailing list