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

Recommended Answers

All 5 Replies

'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

okay my mistake thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.