0
Whata different between if(password.equals("123456") and if(password=="123456") and when should use ==
5 Answers
+ 2
equals is a method in Sting class which compares the exact characters where as == compares address of the two objects
+ 1
can anyone give me example for == compare?.
+ 1
== is used to compare int, double... while equals is used to compare strings.
e.g.:
String a = "abc";
if(a.equals("abc")){
System.out.println("equals");
}
else{
System.out.println("not equal");
}
Output: equals
e.g.:
int a = 123;
if(a==123){
System.out.println("equals");
}
else{
System.out.println("not equal");
}
Output: equals
not sure of the reason but if == is used to compare strings, it will give inaccurate results
+ 1
==compare the reference đ