Add getChars to CharSequence

Martin Buchholz martinrb at
Thu Apr 11 17:14:07 UTC 2013

On Thu, Apr 11, 2013 at 6:36 AM, Alan Bateman <Alan.Bateman at>wrote:

> On 11/04/2013 01:40, Martin Buchholz wrote:
>> I've often wished that CharSequence had getChars methods, as many of the
>> concrete implementations already do.
>> In jdk8 with default methods, this is possible!
>> This will make some of the String code a little nicer and more efficient.
>> Here's a preliminary patch in this direction, that overlaps with some of
>> the work done in
>> 6206780: (str) Forwarding append methods in String{Buffer,Builder} are
>> inconsistent
>> Summary: update StringBuilder & StringBuffer to consistently handle
>> forwarding to AbstractStringBuilder. Some additional cleanup (removal of
>> refs to sub-classes from AbstractStringBuilder)
>> >
>> If we have consensus that this is a good idea, I can flesh this out.
> It's come up a few times and I agree it's worth trying out.
> You should probably add CharBuffer to the list to look at it. At least for
> the 3-arg getChars, then it will need consideration as to whether it works
> as relative bulk get (which it would if not overridden). Also the 5-args
> getChars will treat srcBegin/srcEnd as relative to the current position as
> it stands.

I thought about this a bit.  getChars should be consistent with charAt,
which does not move position and is relative to position.

More information about the core-libs-dev mailing list