Pawan
Pawan

Reputation: 32321

java : Unknown return ('L') type for boolean value

In this method the symbol value can be anything Stock Symbol like (For example GOOG , C , DAC-----etc)

private boolean isC(String symbol) {
    char code = symbol.charAt(symbol.length() - 2);
    return code <= 'L';
}

Could anybody please let me know what does this return type mean exactly ??

I am confused because i was thinking of a return type to be either true or false, but could anybody please let me know what does this 'L' mean exactly ??

Thanks in advance .

Upvotes: 1

Views: 384

Answers (3)

Uchenna Nwanyanwu
Uchenna Nwanyanwu

Reputation: 3204

You can see the ascii code of some of the characters here. code <= 'L' is a comparison between the ascii code of the value of code and 'L'

Upvotes: 0

marc wellman
marc wellman

Reputation: 5886

Because you have a condition stated after the return keyword the condition is getting evaluated first and the result of the evaluation is then getting returned.

And because a condition can only be true or false the return type of this method is boolean.

Here when you apply the <= operator with the type char you are comparing the numerical ASCII representation of a char.

Upvotes: 0

Erik Martino
Erik Martino

Reputation: 4225

returns true if the ascii code of the character in the variable 'code' is less than or equal to the ascii code for L.

false otherwise

Upvotes: 3

Related Questions