how do i compare an object based on two fields

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?
LVL 2
srikoteshAsked:
Who is Participating?
 
CEHJConnect With a Mentor Commented:
Then you would implement equals() based on the equals of both fields
0
 
CEHJCommented:
What do you mean (in plain English) by 'compare'?
0
 
srikoteshAuthor Commented:
I may have 100 students object
I have to compare and I have to take unique objects
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
CEHJCommented:
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
 
srikoteshAuthor Commented:
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
 
awking00Connect With a Mentor Commented:
You may want to use equalsIgnoreCase() if you consider John = JOHN and/or Smith = SMITH
0
All Courses

From novice to tech pro — start learning today.