consider str is a variable of type String.
(1)if( str.toLowerCase() == "answer" )
will ALWAYS NO MATTER WHAT return FALSE.
(2)if( str.equalsIgnoreCase ( "answer" ) )
will return TRUE if the condition is met.
The above is the code I have written for a program. Unfortunately, when I try statement (1) it ALWAYS return false. In other language (I've learned C), the statement is correct. Why is Java interpreting it wrongly?
What is the difference between condition (1) and (2)?
Why is that condition in (1) will always return False?
A long and detailed explanation is highly appreciated. Thx.
2007-10-23
22:54:04
·
5 answers
·
asked by
Akira Matsushima
3
in
Computers & Internet
➔ Programming & Design
Please note that I know about the java syntax. I just need the explanation of why statement (1) is incorrect and statement (2) is correct!
2007-10-23
23:14:10 ·
update #1