Java Programming Example to check whether the two strings are equal or not?

This program accepts the two strings from the keyboard and compare the two strings and display the result whether the two strings are equal or not.

import java.io.*;

/**
 *
 * @author JavaHotSpot
 */

public class stringEqual
{
 public static void main(String args[])
 {

     String s1,s2;
     DataInputStream d;
     try
     {
     System.out.println("Enter the First String");
     d=new DataInputStream(System.in);
     s1=(String)d.readLine();
     System.out.println("Enter the Second String");
     s2=(String)d.readLine();
     if(s1.equals(s2))
     {
         System.out.println("The given strings are Equals");
     }
     else
     {
         System.out.println("The given strings are not Equals");
     }
     }
     catch(Exception e)
     {
         System.out.println(e.toString());
     }
 }
}


Output:

Run 1:
Enter the First String
Java
Enter the Second String
Java
The given strings are Equals


Run 2:
Enter the First String
Java
Enter the Second String
HotSpot