Comparable Interface
1.Comparable is the interface which is present in the java.lang package.
2.We can use this interface to arrange the user defined objects in an order.
3.This interface contains only one method compareTo(Object obj)
4.By using this we can sort the objects based on the single data Member of the objects.
Let ‘a’ and ‘b’ are the two objects.If we want to compare those two objects by using
compareTo(Object obj) method.We can compare like this:
a.compareTo(b);
Here ‘a ’ is called as the target object.Where as ‘b ‘ is called as passed in object.
If the Target Object is less than the Object that is passed in the return value is negative.
if ab return 1;
If the Target Object is equal to the Object that is passed in the return value is Zero.
If a==b return 0;
Solution
Comparable Interface
1.Comparable is the interface which is present in the java.lang package.
2.We can use this interface to arrange the user defined objects in an order.
3.This interface contains only one method compareTo(Object obj)
4.By using this we can sort the objects based on the single data Member of the objects.
Let ‘a’ and ‘b’ are the two objects.If we want to compare those two objects by using
compareTo(Object obj) method.We can compare like this:
a.compareTo(b);
Here ‘a ’ is called as the target object.Where as ‘b ‘ is called as passed in object.
If the Target Object is less than the Object that is passed in the return value is negative.
if ab return 1;
If the Target Object is equal to the Object that is passed in the return value is Zero.
If a==b return 0;

More Related Content

DOCX
Comparable vs comparator
DOCX
Comparable vs comparator
PDF
ComparableThis is the interface which is present in java.lang.pac.pdf
PPT
04a-compare in java operator collection.ppt
PPTX
Unit 3 lecture-2
PDF
in javafx Generic bubble sort The purpose of this exercise i.pdf
PPTX
Comparable/ Comparator
PPT
04a-compare Object orienting programming.ppt
Comparable vs comparator
Comparable vs comparator
ComparableThis is the interface which is present in java.lang.pac.pdf
04a-compare in java operator collection.ppt
Unit 3 lecture-2
in javafx Generic bubble sort The purpose of this exercise i.pdf
Comparable/ Comparator
04a-compare Object orienting programming.ppt

More from reyazansari001 (20)

PDF
You have 50 mL of each solution or .050 L. Molari.pdf
PDF
triosephosphate isomerase .pdf
PDF
Step1 In SO2; sulphur atom is attached to two ele.pdf
PDF
Indicators typically measure pH. The reaction pr.pdf
PDF
i) we dont know the mixture so the reaction may.pdf
PDF
Yes it is always true. The company pays for these resources by eit.pdf
PDF
use good toolsSolutionuse good tools.pdf
PDF
We can consider the following dataThe data is about students from .pdf
PDF
Transposons are the segments of DNA that can move around to differen.pdf
PDF
The middle support should be at a position of (L ÷ square root of 2).pdf
PDF
C)Weak Acid, HF note HF is a weak acid that can.pdf
PDF
test answerSolutiontest answer.pdf
PDF
The answers are well explained & appreciated . The graphs & photos r.pdf
PDF
Stages of cell cycleFlow Cytometry Measurement of Cellular DNA Co.pdf
PDF
Solution.b.Formula = Net income Total stake holder equity 100.pdf
PDF
Solution 1It is clearly mentioned that Facebook is a publicly held.pdf
PDF
Recall Each Oxygen has 4 Electrons in its 2p bonding orbital. But .pdf
PDF
Part 2please rate thanksSolutionPart 2please rate thanks.pdf
PDF
Now, solubility or molarity = 0.41molL Now molarity = moles l.pdf
PDF
Mushroom is the fruiting body of Basidiomycetes fungi. It is also kn.pdf
You have 50 mL of each solution or .050 L. Molari.pdf
triosephosphate isomerase .pdf
Step1 In SO2; sulphur atom is attached to two ele.pdf
Indicators typically measure pH. The reaction pr.pdf
i) we dont know the mixture so the reaction may.pdf
Yes it is always true. The company pays for these resources by eit.pdf
use good toolsSolutionuse good tools.pdf
We can consider the following dataThe data is about students from .pdf
Transposons are the segments of DNA that can move around to differen.pdf
The middle support should be at a position of (L ÷ square root of 2).pdf
C)Weak Acid, HF note HF is a weak acid that can.pdf
test answerSolutiontest answer.pdf
The answers are well explained & appreciated . The graphs & photos r.pdf
Stages of cell cycleFlow Cytometry Measurement of Cellular DNA Co.pdf
Solution.b.Formula = Net income Total stake holder equity 100.pdf
Solution 1It is clearly mentioned that Facebook is a publicly held.pdf
Recall Each Oxygen has 4 Electrons in its 2p bonding orbital. But .pdf
Part 2please rate thanksSolutionPart 2please rate thanks.pdf
Now, solubility or molarity = 0.41molL Now molarity = moles l.pdf
Mushroom is the fruiting body of Basidiomycetes fungi. It is also kn.pdf
Ad

Recently uploaded (20)

PPTX
Computer Architecture Input Output Memory.pptx
PDF
FORM 1 BIOLOGY MIND MAPS and their schemes
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PPTX
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
PDF
Uderstanding digital marketing and marketing stratergie for engaging the digi...
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
PPTX
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
PDF
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
PDF
My India Quiz Book_20210205121199924.pdf
PDF
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
PDF
Empowerment Technology for Senior High School Guide
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PDF
Trump Administration's workforce development strategy
PDF
Complications of Minimal Access-Surgery.pdf
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
Virtual and Augmented Reality in Current Scenario
Computer Architecture Input Output Memory.pptx
FORM 1 BIOLOGY MIND MAPS and their schemes
A powerpoint presentation on the Revised K-10 Science Shaping Paper
CHAPTER IV. MAN AND BIOSPHERE AND ITS TOTALITY.pptx
Uderstanding digital marketing and marketing stratergie for engaging the digi...
Chinmaya Tiranga quiz Grand Finale.pdf
احياء السادس العلمي - الفصل الثالث (التكاثر) منهج متميزين/كلية بغداد/موهوبين
ELIAS-SEZIURE AND EPilepsy semmioan session.pptx
CISA (Certified Information Systems Auditor) Domain-Wise Summary.pdf
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 2).pdf
My India Quiz Book_20210205121199924.pdf
FOISHS ANNUAL IMPLEMENTATION PLAN 2025.pdf
Empowerment Technology for Senior High School Guide
202450812 BayCHI UCSC-SV 20250812 v17.pptx
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
Trump Administration's workforce development strategy
Complications of Minimal Access-Surgery.pdf
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Virtual and Augmented Reality in Current Scenario
Ad

Comparable Interface1.Comparable is the interface which is present.pdf

  • 1. Comparable Interface 1.Comparable is the interface which is present in the java.lang package. 2.We can use this interface to arrange the user defined objects in an order. 3.This interface contains only one method compareTo(Object obj) 4.By using this we can sort the objects based on the single data Member of the objects. Let ‘a’ and ‘b’ are the two objects.If we want to compare those two objects by using compareTo(Object obj) method.We can compare like this: a.compareTo(b); Here ‘a ’ is called as the target object.Where as ‘b ‘ is called as passed in object. If the Target Object is less than the Object that is passed in the return value is negative. if ab return 1; If the Target Object is equal to the Object that is passed in the return value is Zero. If a==b return 0; Solution Comparable Interface 1.Comparable is the interface which is present in the java.lang package. 2.We can use this interface to arrange the user defined objects in an order. 3.This interface contains only one method compareTo(Object obj) 4.By using this we can sort the objects based on the single data Member of the objects. Let ‘a’ and ‘b’ are the two objects.If we want to compare those two objects by using compareTo(Object obj) method.We can compare like this: a.compareTo(b); Here ‘a ’ is called as the target object.Where as ‘b ‘ is called as passed in object. If the Target Object is less than the Object that is passed in the return value is negative. if ab return 1; If the Target Object is equal to the Object that is passed in the return value is Zero. If a==b return 0;