String Handling – equals ( )

equals ( )

Syntax :

   boolean equals (String str);

equals( ) method of String class is used to compare given string with the string of invoking object if both the strings are equal then it will return true otherwise returns false.

class Example

{

public static void main(String arg[ ])

{

String s = “Code project”;

boolean b = s.equals (“Code project”);

System.out.println(b);

System.out.println(s.equals(“code”));

System.out.println(s.equals(“Project”));

System.out.println(s.equals(“Problem”));

System.out.println(s.equals(“Answer”));

}

}

Output:

true

false

false

false

false

Leave a Reply

Your email address will not be published. Required fields are marked *