I tested each statement on its own and it works, but when I use || it ignores the !driver.getText().toString().equals("")part of the statement. Any ideas?
if((!driver.getText().toString().equals(""))|| (canDrive>=0) )
!driver.getText().toString().equals("")
" part - Kirk Woll 2012-04-04 01:58
The ||
operator means or - so if either condition is true, the test succeeds. If you want to both conditions to be true, use &&
.
More reading: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html
If you want to perform both parts of the condition use '|' operator. I.e.
if(driver.getText().toString().length() > 0 | canDrive >= 0)
Though, the left part of the statement should be executed always: http://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.24
If compiler found canDrive >=0 than defiitely it will ignore rest of part of condition because you are using || (or) condition so this will happened,
other wise perfect,
i have tried see the code.
class test{
public static void main(String[] arr){
String str = TestString";
int canDrive = 1;
if(!str.toString().equals("") || canDrive >=0)
System.out.println("pass");
else
System.out.println("fail");
}
}
String.isEmpty()
instead ofequals("")
ulmangt 2012-04-04 01:54