Re: "some text".equals(someString)
E.L. Willighagen writes:
can anyone tell me the difference (performance etc) between:
1. String someString = "text"
if ("some text".equals(someString)) {};
and
2. String someString = "text"
if (someString.equals("some text")) {};
I would think they are pretty much equal with respect to memory
and performance. The compiler compiles static string literals
(like "text" and "some text") to objects of type String. This
means that in both cases you end up with two String objects, one
comparing itself with the other.
To investigate mysterious and possibly compiler dependent details
you can of course try some of Ricks measurement tricks ;-)
--
Regards Jeppe
Reply to: