96. 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.


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:

Download this project:

Click here to download the project containing 'EqualsMethodDemo' class file used in this post (You can download this project and import into Eclipse IDE on your machine)

Please comment below to feedback or ask questions.

How to use the length( ) method to find out the length of a string will be explained in the next post.

No comments: