Solved

how do i compare an object based on two fields

Posted on 2016-11-22
6
28 Views
Last Modified: 2016-11-28
Student object

fname,
lastname,
Address,


i want to compare student object with combination first name and last name
how many ways we can what is the best approach to do it?
0
Comment
Question by:srikotesh
  • 3
  • 2
6 Comments
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
What do you mean (in plain English) by 'compare'?
0
 
LVL 1

Author Comment

by:srikotesh
Comment Utility
I may have 100 students object
I have to compare and I have to take unique objects
0
 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
Student should already have an ID. Does it not have one?
Incidentally, i asked my last question because 'comparing' in Java suggests sorting, not examining difference or equality. The latter is implemented by equals()

If you don't have an ID, you should ask yourself
a. what happens if you have two students called "John Smith"?
b. what happens if you have two students called "John Smith" at the same address (improbable but not impossible)
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 1

Author Comment

by:srikotesh
Comment Utility
i want to compare an object based on two fields
it doesn't have any unique id
by combinatin of two fieds it will be a unique

for sample i took student object

if i have 100 objects those 100 should be unique objects only
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 450 total points
Comment Utility
Then you would implement equals() based on the equals of both fields
0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 50 total points
Comment Utility
You may want to use equalsIgnoreCase() if you consider John = JOHN and/or Smith = SMITH
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
sumDigits  challenge 7 60
count7 challenge 12 67
network + 7 73
@SBGen Method 3 25
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now