In collection sorting comparable and comparator interface will be used..but why this two interfaces required..two will work same purpose so why there are two interfaces instead of one?when to use comparator and when to use comparable?
Answer Posted / obi
In order to implement an interface (such as Comparable) you need access to rewrite a specific class.
If a certain class is given to you as a 'black box' and you now need some way to use a written sort on it - notice that its a black box thus you cannot rewrite any of its code - you would have to create a new class which would act as a Comparator.
| Is This Answer Correct ? | 6 Yes | 0 No |
Post New Answer View All Answers
Which class represents the socket that both the client and server use to communicate with each other?
Why do we need singleton?
why not override thread to make a runnable? : Java thread
What is nextint java?
What does indexof return in java?
How are variables stored?
Is finalize() similar to a destructor?
how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion... ANS:--- >executeupdate method is having boolean return type, if anything goes wrong in data insertion or data updation, it would return false. otherwise, if it successfully inserts data into the database, it would return true NOW HOW TO I CHECK IN MY DURING EXECUTION WHETHER IT RETURNS TRUE OR FALSE... WELL IT WILL DISPLAY ANY MESSAGE OR NOT
What is a parameter in simple terms?
What is constructor and virtual function? Can we call a virtual function in a constructor?
Explain purpose of sleep() method in java?
Compare java and python.
What is the tradeoff between using an unordered array versus an ordered array?
Why string objects are immutable in java?
Is 0 a real number?