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
The given strings are not Equals
Related Articles:
Java Programming Example of how to extract substring from the given string
Java Programming Example of how to remove the extra spaces from the given string
Java Programming Example of how to convert string into bytes
Java Programming Example of how to convert String into characters and display the character?
Java Programming Example of how to replace old character with new character in the string
Java Programming Example to check whether the strings starts with given prefix and ends with given suffix or not?
Java Programming Example of finding the length of the given string
Java Programming Example of concatenation of two strings
Java Programming Example of converting all characters in the string upper case and vise versa
Related Articles:
Java Programming Example of how to extract substring from the given string
Java Programming Example of how to remove the extra spaces from the given string
Java Programming Example of how to convert string into bytes
Java Programming Example of how to convert String into characters and display the character?
Java Programming Example of how to replace old character with new character in the string
Java Programming Example to check whether the strings starts with given prefix and ends with given suffix or not?
Java Programming Example of finding the length of the given string
Java Programming Example of concatenation of two strings
Java Programming Example of converting all characters in the string upper case and vise versa