Solved

how do i compare an object based on two fields

Posted on 2016-11-22
6
55 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
ID: 41897330
What do you mean (in plain English) by 'compare'?
0
 
LVL 2

Author Comment

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

Expert Comment

by:CEHJ
ID: 41897336
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.

 
LVL 2

Author Comment

by:srikotesh
ID: 41897377
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
ID: 41897419
Then you would implement equals() based on the equals of both fields
0
 
LVL 32

Assisted Solution

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nextBoolean(double p) for Random class 3 41
servlet example issue 6 46
Facing this issue for maven proxy setting 2 20
pagenation logic how it is working in my code 1 53
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

840 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