To compare two strings in JAVA there is a equals() functions. if strings are not same this function will return false and if strings are same it will return true. Program below is an example to compare two string. The output of the given program will be "different". Because s1 and s2 is different.
class compare
{
public static void main(String[] args)
{
String s1,s2;
s1="abc";
s2="def";
if(s1.equals(s2))
{
System.out.println("Same");
}
else
{
System.out.println("Different");
}
}
}
READ MORE - How to compare two strings in JAVA :
class compare
{
public static void main(String[] args)
{
String s1,s2;
s1="abc";
s2="def";
if(s1.equals(s2))
{
System.out.println("Same");
}
else
{
System.out.println("Different");
}
}
}