Results 1 to 7 of 7
- 09-09-2010, 12:43 AM #1
Member
- Join Date
- Sep 2010
- Posts
- 11
- Rep Power
- 0
java.util.Comparator Implementation
Hi all ,
Can you please help me understand the following question.I have been attending the interviews .I have been asked this in one of the interview.Thanks in advance.
Assume the following code snippet exists inside a java.util.Comparator implementation.
Fill in the method.
/**
* Compares o1 and o2.
* @return -1 if o1's first name, middle name are lexically less
* than o2's first name, middle name, 0 if o1's first name
* and middle name are lexically the same as o2's,
* and 1 otherwise.
*/
public int compare(Object o1, Object o2) {
// Write your code here.
}
Override the following methods for an implementation of Person:
•
int java.lang.Object.hashCode()
boolean java.lang.Object.equals(Object o)
-
You seem to be missing some things here including:
- The declarations for class fields of Person,
- Code tags (please see my signature link below) and
- Your attempt at a solution first.
Much luck!
- 09-09-2010, 04:41 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 11
- Rep Power
- 0
Hi Sorry,i didn't post the first part of the question here it is
Object Implementation
• Implement a comparator for the Person class that can be used to sort by first name and middle name for the following Interface.
public Interface Person {
String getFirstName();
String getMiddeName();
String getLastName();
Date getBirthDate();
Person[] getParents();
Person[] getChildren();
// etc.
}
- 09-09-2010, 04:43 AM #4
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
- 09-09-2010, 09:28 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
They're a bit out of date as well...that's a Java 1.4 Comparator!
- 11-05-2010, 01:42 AM #6
Member
- Join Date
- Nov 2010
- Posts
- 1
- Rep Power
- 0
@Navatha or others found the answer, if so please post or email me [mod edit: deleted]
Last edited by Fubarable; 11-05-2010 at 01:47 AM. Reason: moderator edit: email address deleted
-
Similar Threads
-
how to use comparator
By KidneyinaCooler in forum Advanced JavaReplies: 2Last Post: 07-18-2010, 10:25 AM -
implements java.util.Comparator<type>
By finn in forum New To JavaReplies: 2Last Post: 05-14-2010, 06:58 PM -
Use different comparator for SortedSet
By linus_k in forum New To JavaReplies: 0Last Post: 11-21-2008, 02:46 PM -
How to search with a Comparator
By Java Tip in forum java.langReplies: 0Last Post: 04-15-2008, 07:39 PM -
java.util
By Java Tutorial in forum Java TutorialReplies: 1Last Post: 02-07-2008, 01:46 PM


LinkBack URL
About LinkBacks


Bookmarks