When your class implements a comparator object, you must implement the compare method. What must be true about the return value from this method when comparing two objects, a and b with a call to a.compare(b) ?
A) It must return 1 if a comes before b, 0 if they are the same, and -1 if a comes after b.
B) It must return -1 if a comes before b, 0 if they are the same, and 1 if a comes after b.
C) It must return a positive value if a comes before b, 0 if they are the same, and a negative value if a comes after b.
D) It must return a negative value if a comes before b, 0 if they are the same, and a positive value if a comes after b.
Correct Answer:
Verified
Q96: Suppose objects a and b are from
Q97: The sort method of the Arrays class
Q98: Given the following code snippet for searching
Q99: The binarySearch method of the Collections class
Q100: The code segment below displays a table
Q103: Complete the following code that is intended
Q104: Suppose you wish to implement the Comparable
Q105: Suppose objects a and b are from
Q106: Which of the following arrays can be
Q107: Suppose the call obj1.compareTo(obj2) returns 0. What
Unlock this Answer For Free Now!
View this answer and more for free by performing one of the following actions
Scan the QR code to install the App and get 2 free unlocks
Unlock quizzes for free by uploading documents