java - when converting an integer value to string the string comparison fails, and returns false boolean value -


public class run {     public static void main(string args[])     {          boolean b;         int i=3;         b=integer.tostring(i)=="3";         system.out.println(b);      } } 

according code should return true,but outputting false.

youre using == when should use:

b=integer.tostring(i).equals("3"); 

i don't know why use x. i'm assuming typo.

basically == compares reference used literal's being compiled in reference new string object created integer that, due implementation details, may or may not have been interned.


Comments

Popular posts from this blog

c# - SelectList with Dictionary, add values to the Dictionary after it's assigned to SelectList -

how can i manage url using .htaccess in php? -

ios - I get the error Property '...' not found on object of type '...' -