Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Advanced-java] Odd question
- From: ejfried@xxxxxxxxxxxxxxxxxxxxx (friedman_hill ernest j)
- Subject: [Advanced-java] Odd question
- Date: Thu, 28 Mar 2002 17:21:07 -0800 (PST)
Hi Alvin,
The other nonsensical replies you've received to the contrary, there
is a method that does precisely what you want. It's
String.intern(). If there's a literal "abc" in your JVM, then new
String("abc").intern() returns it; i.e.,
new String("abc").intern() == "abc"
always. See section 3.10.5 of the JLS for definitive statement that
this is always true.
Sigh. Folks, PLEASE don't reply to messages on mailing lists to say
"maybe it's this" or "have you tried X?" If you don't KNOW, then
you're not contributing; you're just confusing the original poster.
I think Alvin Wang wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi! It is a little odd. Let us say:
>
> String str = new String("abc");
>
> We all know that (str == "abc") is false. My question is how to manipulate
> str to make str point to "abc" (because str knows that its value itself is
> "abc"), or in the other word, to make (str == "abc") true?
>
> Thanks!
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 ejfried@xxxxxxxxxxxxx
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
- References:
- [Advanced-java] Odd question
- From: Alvin Wang
- [Advanced-java] Odd question
- Prev by Date: [Advanced-java] Odd question
- Next by Date: [Advanced-java] Odd question
- Previous by thread: [Advanced-java] Odd question
- Next by thread: [Advanced-java] Odd question
- Index(es):