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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -