Re: Which is more efficient?
From: Jon Skeet (skeet_at_pobox.com)
Date: 10/24/03
- Next message: Zhao: "Question about java.util.Set"
- Previous message: Jon Skeet: "Re: Newbie question - Disadvantages of java"
- In reply to: metfan: "Which is more efficient?"
- Next in thread: metfan: "Re: Which is more efficient?"
- Reply: metfan: "Re: Which is more efficient?"
- Reply: Nils O. Selåsdal: "Re: Which is more efficient?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 24 Oct 2003 08:47:02 +0100
metfan <qjzhupublic@___NoSpam__yahoo.ie> wrote:
> For the following to snips, which one do you think is more efficient?
>
> snip1:
> BufferedWriter bw = new BufferedWriter(new
> OutputStreamWriter(System.out));
> bw.write("abc" + "def");
>
> snip2:
> BufferedWriter bw = new BufferedWriter(new
> OutputStreamWriter(System.out));
> bw.write("abc");
> bw.write("def");
The first, as it compiles to the same as:
BufferedWriter bw = new BufferedWriter(new
OutputStreamWriter(System.out));
bw.write("abcdef");
because literal strings are concatenated at compile time.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Zhao: "Question about java.util.Set"
- Previous message: Jon Skeet: "Re: Newbie question - Disadvantages of java"
- In reply to: metfan: "Which is more efficient?"
- Next in thread: metfan: "Re: Which is more efficient?"
- Reply: metfan: "Re: Which is more efficient?"
- Reply: Nils O. Selåsdal: "Re: Which is more efficient?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|