Re: Which is more efficient?
From: metfan (qjzhupublic_at____NoSpam__yahoo.ie)
Date: 10/24/03
- Next message: Zhao: "Restriction in interface"
- Previous message: Svante Nicholas Arvedahl: "Re: Daylight savings problem"
- In reply to: Jon Skeet: "Re: Which is more efficient?"
- Next in thread: Simon Righarts: "Re: Which is more efficient?"
- Reply: Simon Righarts: "Re: Which is more efficient?"
- Reply: Michael Borgwardt: "Re: Which is more efficient?"
- Reply: Roedy Green: "string literal contatenation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 24 Oct 2003 16:21:25 +0800
>> 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.
>
Well.. what if:
snip1:
BufferedWriter bw = new BufferedWriter(new
OutputStreamWriter(System.out));
String a = new String("abc");
String b = new String("def");
bw.write(a + b);
snip2:
BufferedWriter bw = new BufferedWriter(new
OutputStreamWriter(System.out));
String a = new String("abc");
String b = new String("def");
bw.write(a);
bw.write(b);
-- Best regards, Qingjia Zhu Q@z@J
- Next message: Zhao: "Restriction in interface"
- Previous message: Svante Nicholas Arvedahl: "Re: Daylight savings problem"
- In reply to: Jon Skeet: "Re: Which is more efficient?"
- Next in thread: Simon Righarts: "Re: Which is more efficient?"
- Reply: Simon Righarts: "Re: Which is more efficient?"
- Reply: Michael Borgwardt: "Re: Which is more efficient?"
- Reply: Roedy Green: "string literal contatenation"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|