Computer Science, asked by shrutijain4176, 1 year ago

Explain iterator and comparator with appropriate example.

Answers

Answered by Anonymous
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