explain testing for equality with equalsthats not


Explain Testing for Equality with equals?

That's not what you expected. To contrast strings or any other kind of object you required to use the equals(Object o) techniques from java.lang.String. Below is a corrected version in which works as expected. The purpose for this odd behavior goes fairly deep within Java and the nature of object data types such as strings.
class JackAndJill {

public static void main(String args[]) {

String s1 = new String("Jack went up the hill.");
String s2 = new String("Jack went up the hill.");

if ( s1.equals(s2) ) {
System.out.println("The strings are the same.");
}
else {
System.out.println("The strings are not the same.");
}
}
}

 

Request for Solution File

Ask an Expert for Answer!!
JAVA Programming: explain testing for equality with equalsthats not
Reference No:- TGS0284397

Expected delivery within 24 Hours