equals() method related with content and == operator related with objects
equals method example :
public class Test{
public static void main(String[] args) {
String a = "abc";
String b = "abc";
System.out.println(a.equals(b));
}
}
== operator example :
public class Test{
public static void main(String[] args) {
String c = new String("ab");
String d = new String("ab");
System.out.println(c == d); // different reference
}
}
equals method example :
public class Test{
public static void main(String[] args) {
String a = "abc";
String b = "abc";
System.out.println(a.equals(b));
}
}
== operator example :
public class Test{
public static void main(String[] args) {
String c = new String("ab");
String d = new String("ab");
System.out.println(c == d); // different reference
}
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন