This example illustrates Java string equals method example. In this example both objects posses same value but the type of value is different. Here two types of objects compared one is Integer type and the other one is String type so the method returns false as values types didnot match. Next method returns true if and only if none of the Strings compared posses null value and also must that there value matches each other in sequence, cases and all aspects of equality including value types Method returns true here as both Strings str1 and str2 posses same values, both the String mentioned above don't have any value but still Strings are equal as both are null type objects compared" and finally Method returns false because values of Strings did not match when their respective letters case are concerned.
public class StringEquals { public static void main(String args[]) {
Integer in = new Integer(1234);
String str = new String("1234");
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.