LinuxSA Mailing list archives
Index:
[thread]
[date]
[subject]
[author]
[stats]
From: Barney Wrightson <barney.wrightson@dsto.defence.gov.au>
To : Andrew Reid <andrew.reid@plug.cx>
Date: Mon, 13 Jan 2003 15:42:43 +1030
Re: Java tidbit
Andrew Reid wrote:
> In C, there's sprintf. Comes in handy.
>
> I'm a relative Java newbie. I thought I'd through myself into the
> deep-end and learn by writing an IMAP client. So far, so
> good. However, I've run into a situation where I'd normally use
> sprintf.
>
> Does Java have any way of doing this without concatenating the
> strings? For example, I don't want to have to do:
>
> String test = "My name is " + Firstname + " " + Lastname + ".";
>
> ... as that would be a right pain in the clacker when there are a
> whole bunch of other strings that you want involved.
>
> I found a package[1] that provides C-style printf, sprintf for Java,
> but it would be strange if there wasn't a Java way of doing the same
> thing.
>
> Can one of the Java gurus out there throw me a bone?
>
> Cheers,
>
> - andrew
>
> [1] http://www.braju.com/
>
Standard java is to do what you have there (as far as I know), although
if you are doing a lot of separate appends you should probably use a
StringBuffer for efficiency reasons, as Strings are immutable and so a
new one is created every time you alter the value. The need for sprintf
is lessened because there is always a toString() method for all Objects.
A sprintf clone would need to have a list of Objects passed to it or
something to get around the lack of variable numbers of parameters in java.
Barney
--
LinuxSA WWW: http://www.linuxsa.org.au/ IRC: #linuxsa on irc.openprojects.net
To unsubscribe from the LinuxSA list:
mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject
Index:
[thread]
[date]
[subject]
[author]
[stats]
Return to the LinuxSA Mailing List Information Page