Solved

Comparing objects?

Posted on 1998-10-20
1
183 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Facing this issue for maven proxy setting 2 45
java mysql insert application 14 68
Java 8 to Java 6 8 43
spring maven example issues 3 104
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Suggested Courses

739 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