
Signature
"Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
> > For me standard Java way (for integers and so on):
> >
[quoted text clipped - 6 lines]
> s = String.valueOf(bool);
> There are other String.valueOf(...) methods for all primitive types.
It happens that this method uses exactly the same code in Sun's 1.4.2 as
Boolean.toString(bool) to do that task. But I've discovered that it's
sometimes better to use the static toString method from the appropriate
class instead of String.valueOf. String.valueOf(int), for instance,
passes on the call to Integer.toString(int, 10) and thus assumes
decimal. Likewise for long.
In general, though, one or the other of these is far better than simple
string concatenation.
= Steve =

Signature
Steve W. Jackson
Montgomery, Alabama
>> For me standard Java way (for integers and so on):
>>
[quoted text clipped - 6 lines]
> s = String.valueOf(bool);
> There are other String.valueOf(...) methods for all primitive types.
For me , "" + bool is shorter, clearer and much easier to remember. I
don't understand why I should avoid it. It is one of things that make
Java better than C/C++. I didn't remember about existence of valueOf()
method, and doubt that I will ever use it.
Alan Krueger - 16 Mar 2006 07:22 GMT
> For me , "" + bool is shorter, clearer and much easier to remember. I
> don't understand why I should avoid it.
Because that compiles into this:
StringBuffer temp = new StringBuffer();
temp.append(bool);
s = temp.toString();
Boolean.toString() simply returns a static string, no construction
necessary.
Hendrik Maryns - 16 Mar 2006 10:53 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
NotDashEscaped: You need GnuPG to verify this message
Mishagam schreef:
>>> For me standard Java way (for integers and so on):
>>>
[quoted text clipped - 11 lines]
> Java better than C/C++. I didn't remember about existence of valueOf()
> method, and doubt that I will ever use it.
Except from Alan's comment, I strongly disagree that this is clean and
legible code. It is a trick. You have to know details of Java syntax
to know it, whereas String.valueOf(boolean) or Boolean.toString(boolean)
comply to the standard static method syntax.
H.

Signature
Hendrik Maryns
==================
www.lieverleven.be
http://aouw.org