Java Programs to check if Strings are equal

Here is a simple java program to show whether the entered strings are equal or not….

import java.io.*;
class streq
{
public static void main(String args[]) throws IOException
{
System.out.println(“enter the first string”);
DataInputStream ds1 = new DataInputStream(System.in);
String str1 = ds1.readLine();
System.out.println(“Enter the second string”);
DataInputStream ds2 = new DataInputStream(System.in);
String str2 = ds2.readLine();
if(str1.equals(str2))
System.out.println(“the strings are equal”);
else
System.out.println(“the strings are not equal”);
}
}

Add Comment