Explain testing for equality with equals, JAVA Programming

Assignment Help:

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.");
}
}
}

 


Related Discussions:- Explain testing for equality with equals

I want java a web technologies expertise, I want Java a Web Technologies ex...

I want Java a Web Technologies expertise Project Description: Good Java knowledge about 4-5 years to develop online enterprise tool. Seeking someone who is interested to w

Mine craft plug-in coder, Mine craft plug-in Coder Project Description: ...

Mine craft plug-in Coder Project Description: Some custom plugging for my Mine craft server. Skills required: Java, Editing

What is overriding, What is Overriding? When a class explains a method ...

What is Overriding? When a class explains a method using the similar name, return type, and arguments as a method in its superclass, the method in the class overrides the metho

Calculate the kilometer within an hour, Calculate the kilometer within an h...

Calculate the kilometer within an hour? class Car { String licensePlate = ""; // e.g. "New York 543 A23" double speed = 0.0; // in kilometers per hour doubl

Want a script developer, I want a Script developer who will make script for...

I want a Script developer who will make script for me and if you can show good works there are bonuses too. Skills required are Facebook Marketing, Java, Javascript, PHP, and Sc

Android apk for 3g dongles support, ANDROID APK for 3G dongles support P...

ANDROID APK for 3G dongles support Project Description: We want someone who will modify this Android app or code a similar one. The App function is to let Android tablet P

I want school management project, I want School Management project Proje...

I want School Management project Project Description: An easy school management project which able to store all data about students like fees structure, admission details and

Pebblemerchant, how to write a java program for pebble merchant

how to write a java program for pebble merchant

What is an applets, What is an Applets? Applets: These are small java...

What is an Applets? Applets: These are small java programs. They can send from one to another computer over internet by using Applet Viewer which supports java. Applets

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd