A: In Java, equals() method is used to compare the contents of two string objects and returns true if the two have same value while == operator compares the references of two string objects.
In the following example, equals() returns true as the two string objects have same values. However == operator returns false as both string objects are referencing to different objects:
public class equalsTest {public static void main(String args[]) {String srt1="Hello World";String str2="Hello World";if (str1.equals(str2)){// this condition is trueSystem.out.println("str1 and str2 are equal in terms of values");}if (str1==str2) {//This condition is not trueSystem.out.println("Both strings are referencing same object");}else{// This condition is trueSystem.out.println("Both strings are referencing different objects");}}}