String compare
Input : ABCD, XYZ
Output : ABCD is not equal to XYZ
XYZ is greater than ABCD
Input : Geeks, forGeeks
Output : Geeks is not equal to forGeeks
forGeeks is greater than Geeks
String compare
Input : ABCD, XYZ
Output : ABCD is not equal to XYZ
XYZ is greater than ABCD
Input : Geeks, forGeeks
Output : Geeks is not equal to forGeeks
forGeeks is greater than Geeks
Java compare two strings
// compare two strings in java using String.equals() method in java
public class EqualsMethodDemo
{
public static void main(String[] args)
{
String str1 = new String("HelloWorld");
String str2 = new String("Flower");
String str3 = new String("Hello");
String str4 = new String("Hello");
String str5 = new String("hello");
// compare str1 != str2
System.out.println("Compare " + str1 + " and " + str2 + ": " + str1.equals(str2));
// compare str3 = str4
System.out.println("Compare " + str3 + " and " + str4 + ": " + str3.equals(str4));
// compare str4 != str5
System.out.println("Compare " + str4 + " and " + str5 + ": " + str4.equals(str5));
// compare str1 != str4
System.out.println("Compare " + str1 + " and " + str4 + ": " + str1.equals(str4));
}
}
String compare
Input : ABCD, XYZ
Output : ABCD is not equal to XYZ
XYZ is greater than ABCD
Input : Geeks, forGeeks
Output : Geeks is not equal to forGeeks
forGeeks is greater than Geeks
Java compare two strings
// compare two strings in java using String.equals() method in java
public class EqualsMethodDemo
{
public static void main(String[] args)
{
String str1 = new String("HelloWorld");
String str2 = new String("Flower");
String str3 = new String("Hello");
String str4 = new String("Hello");
String str5 = new String("hello");
// compare str1 != str2
System.out.println("Compare " + str1 + " and " + str2 + ": " + str1.equals(str2));
// compare str3 = str4
System.out.println("Compare " + str3 + " and " + str4 + ": " + str3.equals(str4));
// compare str4 != str5
System.out.println("Compare " + str4 + " and " + str5 + ": " + str4.equals(str5));
// compare str1 != str4
System.out.println("Compare " + str1 + " and " + str4 + ": " + str1.equals(str4));
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us