Possible Duplicate:
How do I compare strings in Java?
I have a boolean statement that should evaluate to true
due to the incorrect use of !=
to compare strings:
public int calculateWeight( String hostname, String parameter,
String parInstance ) throws InvalidWeightException
{
if ( parameter != "*" && hostname != "*" && parInstance != "*" )
{
return 1;
}
...
}
When debugging a JUnit test that calls this method, the if statement is evaluating to true (via Eclipse Inspect) yet the return
statement does not execute. The value passed to parInstance
variable is actually "*"
. If we use !(.equals())
, the Eclipse Inspect shows false
as expected.