Path: csiph.com!2.us.feeder.erje.net!feeder.erje.net!1.eu.feeder.erje.net!news.unit0.net!news.netfront.net!.POSTED.87.142.8.24!not-for-mail From: Lothar Kimmeringer Newsgroups: comp.lang.java.programmer Subject: Re: "Double.toString" Date: Sun, 20 Nov 2016 22:49:30 +0100 Organization: Organization?! Only chaos here! Message-ID: <1u072gaozj278$.dlg@kimmeringer.de> References: Reply-To: news@kimmeringer.de Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Injection-Info: adenine.netfront.net; posting-host="87.142.8.24"; logging-data="26182"; mail-complaints-to="news@netfront.net" User-Agent: 40tude_Dialog/2.0.15.1de Xref: csiph.com comp.lang.java.programmer:35910 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). Cheers, Lothar -- Lothar Kimmeringer E-Mail: spamfang@kimmeringer.de PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81) Always remember: The answer is forty-two, there can only be wrong questions!