Using 'equals( )' method for comparing two strings

You can compare two strings using equals( ) predefined method and find out whether the two strings are same or not.

Example:

String myString1 = "This is a String text";
String myString2 = "This is a String text";

System.out.println( myString1.equals(myString2) );

Let implement this example on Eclipse IDE:

1.Create 'EqualsMethodDemo' class under any project as shown below:



2. Save and Run the 'EqualsMethodDemo' class file
3. Observe that the output is displayed in the console as shown below: