Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #35934
| Newsgroups | comp.lang.java.programmer |
|---|---|
| Date | 2016-11-22 15:10 -0800 |
| References | <Double-toString-20161119164723@ram.dialup.fu-berlin.de> <o0s8u2$rj6$1@dont-email.me> <1u072gaozj278$.dlg@kimmeringer.de> |
| Message-ID | <9a71ae21-aa0e-4ee6-930f-b7b871a8d7cc@googlegroups.com> (permalink) |
| Subject | Re: "Double.toString" |
| From | lewbloch@gmail.com |
On Sunday, November 20, 2016 at 1:49:48 PM UTC-8, Lothar Kimmeringer wrote:
> Eric Sosman wrote:
>
> > I wouldn't say "prominent," simply because I don't use it much:
> > Whenever I want Java's string version of a double, I usually want it
> > in combination with another string. So I write
> >
> > System.out.println("\u03c0 \u2248 " + Math.PI);
> >
> > ... and let Java fill in the toString() method call.
>
> The resulting code being created by the compiler is quite
> more complicated with this rather than doing
> Double.toString(Math.PI). Your example isn't that bad, but
> the most common way to create a String from a double
> myString = "" + myDoubleValue
> results in something like this:
> myString = new StringBuilder()
> .append("")
> .append(String.valueOf(myDoubleValue)
> .toString();
>
> The number of objects being created is way higher than when
> simply calling Double.toString(myDoubleValue). I read about
> that in an article once and used the toString()-methods
> ever since (makes code more readable IMHO as well).
The number of objects created is very unlikely to present an issue. The `StringBuilder` will be GCed painlessly, and the HotSpot is likely to optimize away a whole lot of that anyway. Let's not panic about the negligible putative differences in performance and focus on clarity and maintainability of the source.
--
Lew
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: "Double.toString" Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-11-20 08:37 -0500
Re: "Double.toString" Lothar Kimmeringer <news200709@kimmeringer.de> - 2016-11-20 22:49 +0100
Re: "Double.toString" Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-11-21 08:25 -0500
Re: "Double.toString" lewbloch@gmail.com - 2016-11-22 15:10 -0800
Re: "Double.toString" Lothar Kimmeringer <news200709@kimmeringer.de> - 2016-11-24 14:07 +0100
Re: "Double.toString" Arne Vajhøj <arne@vajhoej.dk> - 2016-11-24 11:12 -0500
Re: "Double.toString" lewbloch@gmail.com - 2016-11-27 08:16 -0800
Re: "Double.toString" Eric Douglas <e.d.programmer@gmail.com> - 2016-11-28 05:34 -0800
csiph-web