Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #26234
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: StringBuilder.append and CharSequence |
| Date | 2013-10-05 12:51 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnl502pq.mol.avl@gamma.logic.tuwien.ac.at> (permalink) |
| References | (3 earlier) <52448f70$0$303$14726298@news.sunsite.dk> <slrnl497c6.mol.avl@gamma.logic.tuwien.ac.at> <5244a015$0$302$14726298@news.sunsite.dk> <slrnl4avs3.mol.avl@gamma.logic.tuwien.ac.at> <524f6470$0$302$14726298@news.sunsite.dk> |
Arne Vajhøj <arne@vajhoej.dk> wrote:
> On 9/27/2013 8:52 AM, Andreas Leitgeb wrote:
>> If a CharSequence is a vehicle to transport the char and the number
>> into StringBuilder's reach, then this is some big boilerplate substitute
>> for the sorely missing .append(int num, char ch) method, but not goofy.
>>
>> If this CharSequence was then merely used to create a big dull
>> temp object via toString(), then it goes right back to "goofy".
> I would not worry about temporary object being created
> unless I observe an actual problem.
I had considered this thread done already, but since there is further
interest...
There's really two aspects to my original problem.
1) will any temporary object be created when append()ing a CharSequence
to a StringBuilder?
2) might StringBuilder eventually call a CharSequence's toString() from
within it's .append()?
A positive answer for 2) would also imply "yes" for 1), of course.
Given the *current* implementation of Oracle's implementation,
the answer to both questions is (fortunately) negative.
Even the consequences of a "1) yes 2) no" reply would not really be
as "earth-shattering" as I might have implied so far in this thread.
Now, for question 2)
There'll be essentially two kinds of CharSequence implementations:
a) some kind of "mutable String-alike", like e.g. StringBuilder.
these likely save their data in some char[] already, and
creating a String of that is trivial.
b) those that "calculate" each char in charAt().
My ChSeq falls into that category, and maybe a couple other
special purpose ones.
For those of kind b), being allowed to slam "this" to a StringBuilder
and then have the StringBuilder create a String object, would sound like
a nice example of code-reuse, compared to having to write the loop and
append-call for each char.
I don't really have any idea, how many CharSequence implementations
of kind b) really exist in the world, and it is not unlikely, that
they are far too few to justify any thought at all, but nevertheless,
I wish that StringBuilder.append() were SPECIFIED to use CharSequence-
API (i.e. essentially length() and charAt(), as is already implemented)
to SAFELY allow for trivial .toString() implementations in those classes.
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-25 14:19 +0000
Re: StringBuilder.append and CharSequence markspace <markspace@nospam.nospam> - 2013-09-25 13:02 -0700
Re: StringBuilder.append and CharSequence markspace <markspace@nospam.nospam> - 2013-09-25 18:34 -0700
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-26 17:37 +0000
Re: StringBuilder.append and CharSequence Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-09-26 23:11 +0200
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-27 13:30 +0000
Re: StringBuilder.append and CharSequence Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-09-27 19:31 +0200
Re: StringBuilder.append and CharSequence markspace <markspace@nospam.nospam> - 2013-09-27 13:45 -0700
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-27 23:16 +0000
Re: StringBuilder.append and CharSequence Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2013-09-29 04:58 +0200
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-30 20:02 +0000
Re: StringBuilder.append and CharSequence Arne Vajhøj <arne@vajhoej.dk> - 2013-09-25 20:57 -0400
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-26 18:01 +0000
Re: StringBuilder.append and CharSequence Arne Vajhøj <arne@vajhoej.dk> - 2013-09-26 15:47 -0400
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-26 20:48 +0000
Re: StringBuilder.append and CharSequence Arne Vajhøj <arne@vajhoej.dk> - 2013-09-26 16:58 -0400
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-09-27 12:52 +0000
Re: StringBuilder.append and CharSequence Arne Vajhøj <arne@vajhoej.dk> - 2013-10-04 20:59 -0400
Re: StringBuilder.append and CharSequence Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2013-10-05 12:51 +0000
Re: StringBuilder.append and CharSequence Sven Köhler <remove-sven.koehler@gmail.com> - 2013-09-27 15:41 +0300
csiph-web