String Initialisation

I s there any difference in String initialized at the pt of definition Constructor Init
[94 byte] By [tshota] at [2007-10-3 3:05:03]
# 1
> I s there any difference in String initialized at the> pt of definition Constructor Initwhat are you talking about? do you mind rephrasing your question.
lupansanseia at 2007-7-14 20:55:07 > top of Java-index,Java Essentials,New To Java...
# 2

/cracks knuckles/ All right, I've done some Sloppy-to-English translation in my time...Is this what you meant?

"Is there any difference between initializing a String when you declare it, and initializing it in a Constructor?"

Well, Strings should only be initialized in a constructor if they're instance members...if your String is a method variable or a class member it's not good constructor material.

Platonixa at 2007-7-14 20:55:07 > top of Java-index,Java Essentials,New To Java...
# 3

String s = "my string";

is logical same as

String s = new String("my string");

But first variant is more efficient . When we create new String using constructor there are created two stings. First is created by compiler, when it founds constant string - "my string". And second is our String object s.

Message was edited by:

jogurtIR

jogurtIRa at 2007-7-14 20:55:07 > top of Java-index,Java Essentials,New To Java...