Monday 16 June 2014

equals (Object anObject)

public boolean equals(Object anObject)
Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

class StringEquals{
 public static void main(String args[]){
  String s1 = new String("Hello");
  String s2 = new String("Hii");
  String s3 = new String("Hello");
  Integer i = new Integer(10);
  
  System.out.print("Is s1 and s2 are equal ");
  System.out.println(s1.equals(s2));
  System.out.print("Is s1 and s3 are equal ");
  System.out.println(s1.equals(s3));
  System.out.print("Is s1 and i are equal ");
  System.out.println(s1.equals(i));
 }
}

Output
Is s1 and s2 are equal false
Is s1 and s3 are equal true
Is s1 and i are equal false


Prevoius                                                 Next                                                 Home

No comments:

Post a Comment