Solved

Comparing objects?

Posted on 1998-10-20
1
182 Views
Last Modified: 2010-03-30
Is there any method that allows you to compare objects to see if they are equal???

0
Comment
Question by:wazila
1 Comment
 
LVL 2

Accepted Solution

by:
mwibbels earned 20 total points
ID: 1226001
Every object has a method equals(Object o) which checks if two objects are equal, so a.equals(b) returns true if a equals b. You can override this method (as has been done in the String class) to let your own classes compare.

Keep in mind that, for Strings a and b, the expression "a.equals(b)" is not the same as "a==b": the first compares the contents of two strings, the second compares their references.

Most overrides of "equals" first check if both objects are instances of the same class and then compare their contents.

Also check the Object and String documentation of the "equals" method.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
difference of if loops 23 62
Java exception bubble up 2 21
Java Restore security prompts not working 10 73
Eclipse for Java EE development 2 28
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question