when using equals method with a null string...
- From: minjie@xxxxxxxxxx
- Date: 10 Mar 2006 07:22:03 -0800
If I have declared 2 strings as follows:
private String myStr1 = "";
private String myStr2 = "";
and somewhere in the application they may or may not get assigned
values. When I do
if (myStr1.equals(myStr2))
....
I will get an exception if myStr1 is null. How do I test it without
using
if (myStr1 != null)
if (myStr1.equals(myStr2))
....
?
I have a lot of string comparisons like the above, and if I have to
test one by one like that, it's a lot of code!
Thanks.
.
- Follow-Ups:
- Re: when using equals method with a null string...
- From: steve
- Re: when using equals method with a null string...
- From: Thomas Hawtin
- Re: when using equals method with a null string...
- From: Tony Burrows
- Re: when using equals method with a null string...
- From: Ed Kirwan
- Re: when using equals method with a null string...
- From: mike
- Re: when using equals method with a null string...
- From: Tony Burrows
- Re: when using equals method with a null string...
- Prev by Date: Re: Reading delimited gzipped serialized objects
- Next by Date: Re: A good Java (not enterprise) code design book?
- Previous by thread: Compiler telling me I have 1.4 JDK when i have 1.5 wont compile generics code
- Next by thread: Re: when using equals method with a null string...
- Index(es):
Relevant Pages
|