public class StringsComparison {
	public static void main(String[] args) {
		String str1 = "John";
		String str2 = "Joe";
		String str3 = "Joh";
		str3 += "n";
		System.out.println("str1: \"" + str1 + "\"");
		System.out.println("str2: \"" + str2 + "\"");
		System.out.println("str3: \"" + str3 + "\"");
		// test two strings for equality
		if (str1.equals(str2))
			System.out.println("str1 and str2 are EQUAL");
		else
			System.out.println("str1 and str2 are NOT EQUAL");
		// "==" won't work, use equals instead
		if (str1 == str3)
			System.out.print("str1 == str2");
		else
			System.out.print("str1 != str2");
		System.out.print(", but ");
		if (str1.equals(str3))
			System.out.println("str1.equals(str2) is true");
		else
			System.out.println("str1.equals(str2) is false");
		// compare two strings in lexicographic order
		if (str1.compareTo(str2) < 0)
			System.out.println("str1 < str2");
		else if (str1.compareTo(str2) > 0)
			System.out.println("str1 > str2");
		else
			System.out.println("str1 equals to str2");
		// another example of comparison
		if (str1.compareTo(str3) < 0)
			System.out.println("str1 < str3");
		else if (str1.compareTo(str3) > 0)
			System.out.println("str1 > str32");
		else
			System.out.println("str1 equals to str3");
	}
}
