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' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -