Solved

Comparing objects?

Posted on 1998-10-20
1
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

622 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