Note -- ‘equals()’ method check for the content equality
Operator will check object.. whether object is same or not
public class EqualsMethod {
public static void main(String[] args) {
String s1 = new String("bala");
String s2 = new String("bala");
if (s1.equals(s2)) // using equals method
{
System.out.println("Content are same -- TRUE");
} else {
System.out.println("Content are different -- FALSE");
}
if (s1 == s2) // using operator
{
System.out.println("Object is same -- TRUE");
} else {
System.out.println("Object is different -- FALSE");
}
}
}
Operator will check object.. whether object is same or not
public class EqualsMethod {
public static void main(String[] args) {
String s1 = new String("bala");
String s2 = new String("bala");
if (s1.equals(s2)) // using equals method
{
System.out.println("Content are same -- TRUE");
} else {
System.out.println("Content are different -- FALSE");
}
if (s1 == s2) // using operator
{
System.out.println("Object is same -- TRUE");
} else {
System.out.println("Object is different -- FALSE");
}
}
}
No comments:
Post a Comment