In this tutorial, we are going to learn a java program to check if two strings that are given input by the user are the same or not. For any two input strings, we have to check if strings are same or not. In this program we are not checking the case sensitivity of the strings.
For Example
Case1: If the user input the string ‘Quescol’ as the first string and ‘Quescol’ as the second string,
The output should be ‘Both strings are same’.
Case2: If the user input the string ‘Quescol’ as the first string and ‘quescol’ as the second string,
The output should be ‘Both strings are same’.
Case3: If the user input the string ‘Quescol’ as the first string and ‘website’ as the second string,
The output should be ‘Both strings are not same’.
Java Program to check if Strings are equal or not
Output
Explanations
In this example, the first string is taken as ‘Quescol’ and the second string is ‘quescol’, as we can see both strings are identical so the output return is ‘Strings are equal’.