Compare Two Strings
This program compares two strings for equality.
Problem Statement
Write a Java program to compare two strings.
Source Code
| 1 | public class StringComparison { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq String Comparison"); |
| 4 | String s1="Eduinq", s2="Eduinq"; |
| 5 | if(s1.equals(s2)) System.out.println("Strings are equal"); |
| 6 | else System.out.println("Strings are not equal"); |
| 7 | } |
| 8 | } |
Program Output
Eduinq String Comparison Strings are equal
Explanation
Strings compared using equals() method. - Returns true if both strings have same content. - Together demonstrates string comparison. Conclusion: Shows how to compare two strings.