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
The equals() method compares the two strings for content equality, returning true only if both strings hold the exact same characters, demonstrating proper string comparison.