Explain iterator and comparator with appropriate example.
Answers
Answered by
0
Comparable is used to compare itself by using with another object. Comparator is used to compare two datatypes are objects. If you see then logical difference between these two is Comparator in Java compare two objects provided to him, while Comparable interface compares "this" reference with the object specified.Java provides us facility to create our own exceptions which are basically derived classes of Exception. For example MyException in below code extends the Exception class. We pass the string to the constructor of the super class- Exception which is obtained using “getMessage()” function on the object created.
Similar questions
Social Sciences,
7 months ago
Math,
7 months ago
Social Sciences,
7 months ago
Science,
1 year ago
Physics,
1 year ago
Science,
1 year ago
Math,
1 year ago