hi james

can you explain to me why every time I tried to used this line of code, i keep getting a syntax error.

if(code.equals('L') || code.equals('l'))

did i miss something, did i leave out someting

2 Years
Discussion Span
Last Post by Stephen_8

'l' is for a char, most likely, code is a String and you'll need:

if ( code.equals("L") || code.equals("l") )

which, in case of String comparison, can be changed by:

if ( code.equalsIgnoreCase("L") )

if code is a char, on the other hand, you may want to use:

if ( code == 'L' || code == 'l' )

for future reference: we don't know your code, so telling us what datatype code is, and what syntax error is mentioned, might help us out in being more specific in helping you.


Stephen: it won't help very much, except maybe in concept.
The article you link to is for .NET, the question for Java.

In Java, the difference between "==" and ".Equals(Object o)" is:
the == operator compares referential equality.
.Equals is a compile time error, since it doesn't exist.


okay stultuske, thanks very much

hey stultuske nice to hear from you havent heard from u in a while

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.