Java Program to Check if two Strings are the Same(Case Sensitivity)

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.

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 not 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 Two Strings are equal or not( Case Sensitivity)

Output 1

Explanations

In this example, the first string is taken as ‘Quescol’ and the second string is ‘quescol’, as we can see both strings are not identical, as Q is in capital letter in first input and in second input q is smaller. So the output return is ‘Strings are not equal’.

Output 2

Output

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