Re: "some text".equals(someString)
- To: debian-java@lists.debian.org
- Subject: Re: "some text".equals(someString)
- From: Arnaud Vandyck <arnaud.vandyck@ulg.ac.be>
- Date: Tue, 29 Jan 2002 10:03:42 +0100 (CET)
- Message-id: <[🔎] 20020129.100342.41639996.arnaud.vandyck@ulg.ac.be>
- In-reply-to: <[🔎] 20020129082408.75414.qmail@web20210.mail.yahoo.com>
- References: <[🔎] 200201290752.g0T7q6I15054@ac9.sci.kun.nl> <[🔎] 20020129082408.75414.qmail@web20210.mail.yahoo.com>
Francois BOTTIN <frbottin@yahoo.fr> wrote:
> --- "E.L. Willighagen" <egonw@sci.kun.nl> wrote:
> >
> > Hi all,
> >
> > 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 don't know if there's a difference in performance (and it will
> certainly depend of the JVM implementation).
I do not think there is a difference.
> Personnaly I use the first alternative as it permits null values for
> someString without throwing a NullPointerException.
So do I.
> It's also possible to have someString that's not declared as a
> String (you don't need to cast it, and hence avoid a
> ClassCastException).
Well, .equals(Object) is an Object method, so you'll never have a
casting probleme. Even for a String, myString.equals(Object) and NOT
myString.equals(String)
java.lang
Class String
java.lang.Object
|
+--java.lang.String
+---------------+----------------------------------------------------+
| boolean | equals(Object anObject) |
| | Compares this string to the specified |
| | object. |
+---------------+----------------------------------------------------+
-- Arnaud, STE-Formations Informatiques, fapse, ULg, .BE
Reply to:
- References:
- "some text".equals(someString)
- From: "E.L. Willighagen" <egonw@sci.kun.nl>
- Re: "some text".equals(someString)
- From: Francois BOTTIN <frbottin@yahoo.fr>
- "some text".equals(someString)
- Prev by Date: Re: "some text".equals(someString)
- Next by Date: Re: "some text".equals(someString)
- Previous by thread: Re: "some text".equals(someString)
- Next by thread: Re: "some text".equals(someString)
- Index(es):