How this line is executed in java? -


i trying compare character ascii values using bellow code.it works fine have doubt.how bellow line executed. didn't convert s.charat(i) int how compared ascii value.

code 1:

if(s.charat(i)>='a' && s.charat(i)<='z'){ } 

code 2:

if((int)s.charat(i)>='a' && (int)s.charat(i)<='z'){ } 

in above 2 codes working same.i need know difference between code1 , code2. can 1 me know this?

the comparison operators work on numerical operands -- or, more specifically, on operands can converted numerical operands (jls 15.20.1). in "code 1" example, 4 chars (two s.charat(i), , 2 literals) automatically promoted int purposes of comparison.

the first step of comparison use "binary numeric conversion" both operands of same type (jls 5.6.2). basically, they're widened narrowest type can accommodate both types, in case of char int. once that's done, it's straightforward, signed comparison.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -