Jacob Nikom wrote:
>
> Hi,
>
> This is not really Java-Linux, but more like Java question.
> May be it is different for Java Linux implementation, that is
> why I decided to ask.
>
> My friend and I recently tried to figure out which String
> implementation is more efficient and correct:
>
> String a = "bbbbbb"
>
> or
>
> String a = new String("bbbbbb");
>
> He said that the second one is a copy constructor which is less
> efficient. It uses more memory and requires to copy the array
> from one place to another. I said that they are the same and it is
> simply different syntax. Who is right?
>From what I've read, they are exactly equivalent. The first
type is a syntax shortcut built into the language only for strings,
because using strings is so very common. Strings are the only
non-primitive type which allows this syntax.
Functionally the compiler turns the first into the second.
I suppose the definitive answer can be found by writing a simple
class and running javap on it to disassemble the bytecodes and
compare them.
--
Joi Ellis Software Engineer
Aravox Technologies [EMAIL PROTECTED], [EMAIL PROTECTED]
No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried. Anything
that kicks a monopoly in the pants has got to be good for something.
- Chris Johnson
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]