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

Non-final functions in java object class, Normal 0 false fals...

Normal 0 false false false EN-US X-NONE X-NONE

Ask to do it, Ask question #Minig cbhdsjamkvfdsk mum 100 words accepted#

Ask question #Minig cbhdsjamkvfdsk mum 100 words accepted#

I need ios native app developer, I want someone to help me prepare a simple...

I want someone to help me prepare a simple inventory system. I am not a programmer trying to learn as i go. Skills required: Android, Java, iPhone, Mobile Phone, Objective

Jsf framework compare with the struts framework, Struts framework ...

Struts framework                            J a v a Server Faces More matured since Struts has been started for a few years. It has got var

Data structures, Can I please get your help in my assignment and a quote if...

Can I please get your help in my assignment and a quote if possible

Develop the back end of a calculator application, For this assignment, you ...

For this assignment, you will develop the back end of a calculator application. The GUI (graphical user interface) has been provided by your instructor. The application will requir

Explain the char data type in java, Explain the char data type in java? ...

Explain the char data type in java? A char is a single character in which a letter, a digit, a punctuation mark, a tab, a space or something same. A char literal is a single on

Game, any example of games that is created by java ?

any example of games that is created by java ?

Instance of a SyntaxTree object is null. I don''t know why.?, I have been w...

I have been working on my compiler''s parser now. And for some reason i cant make my parse tree printer to work. SyntaxTree keeps on showing as null when i invoke the print() metho

What is java rmi, Remote Method Invocation (RMI) is the process of activati...

Remote Method Invocation (RMI) is the process of activating a method on a remotely running object. RMI offers location transparency in the sense that it gives the feel that a metho

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