M
minjie
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.
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.