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:
3. Observe that the output is displayed in the console as shown below:
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:
Post a Comment