when using equals method with a null string...



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.

.



Relevant Pages

  • Re: Structured exception information
    ... Tcl is a powerful language that is quite successful ... I said "Strings are the correct type for presenting information to the ... And yes, Ada exceptions ... But I don't understand _why_ you want to do that in the exception ...
    (comp.lang.ada)
  • Re: Structured exception information
    ... the programmers, I don't think that approach will produce good error ... involved in exception raising and exception handling in the ... But when the exceptions were reported as strings into some log ... program and can be arranged for Ada coverage rules. ...
    (comp.lang.ada)
  • Re: when using equals method with a null string...
    ... I will get an exception if myStr1 is null. ... I have a lot of string comparisons like the above, ... www.EdmundKirwan.com - Home of The Fractal Class Composition. ...
    (comp.lang.java.programmer)
  • Re: [ANN] Data Source Name parser (ODBC etc.)
    ... > suggested URL-like strings describing database connections. ... > library for such strings (data source names) is now available at ... raises the exception Syntax_Error. ...
    (comp.lang.ada)
  • Re: RTTI and dynamic_cast<> implementations in VC++.NET
    ... >extensively and only resort to C-style strings when absolutely necessary. ... String comparisons seems the most obvious way. ... and even then many libraries provide ... C++ FAQ: http://www.parashift.com/c++-faq-lite/ ...
    (microsoft.public.vc.language)