• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 83
  • Last Modified:

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?
0
srikotesh
Asked:
srikotesh
  • 3
  • 2
2 Solutions
 
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
 
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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

 
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
 
CEHJCommented:
Then you would implement equals() based on the equals of both fields
0
 
awking00Commented:
You may want to use equalsIgnoreCase() if you consider John = JOHN and/or Smith = SMITH
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now