Solved

how do i compare an object based on two fields

Posted on 2016-11-22
6
64 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
[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
  • 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 95
SHA2 certs for IIS AND Java? 2 136
Java exception bubble up 2 26
Where to place postgres JDBC driver jar on tomcat 8 71
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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
The viewer will learn how to implement Singleton Design Pattern in Java.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

751 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