Write a Java Program to compare two strings.
Click Here to View the Solution!
Click Here to View the Output!
Click Here to View the Explanation!
- This program deals with the comparison between two strings by employing
- In comparison with the previous example, strings in this example are produced by employing
- In the
equals ()method takes
style2string as an argument, and is called upon
styleto compare the contents.
- In the previous example, referencing was being compared instead of actual contents.
- The console displays ‘Equal’ if the contents of strings are identical and ‘Not Equal’ otherwise.
- The Output is ‘ Not Equal’ as the contents of both strings are not identical.
- Output would have been “ Equal”, if both strings were identical.