Purchase Solution

Why aren't relational operator (==) and the .equals method interchangeable?

Not what you're looking for?

Ask Custom Question

Why aren't the relational operator (==) and the .equals method interchangeable? Why isn't the following code correct?

String myName = "Ken";
if (myName == "Ken")
//do something

Purchase this Solution

Solution Summary

This response provides a tutorial correcting the relational operation and the .equals method.

Solution Preview

The "==" operator and the .equals method are not interchangeable.
"==" operator is to compare the references of two variables, .equals method is to compare the value of the two objects.

In your example, ...

Purchase this Solution


Free BrainMass Quizzes
C++ Operators

This quiz tests a student's knowledge about C++ operators.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Javscript Basics

Quiz on basics of javascript programming language.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.