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 / 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 |
Can we override the main method?
How do you reverse a string in java?
Define a java class.
long d =10;int i =0;i=d; /// is this possible? If d is very long number (10 digits or some thing) then?
what is main difference between architecture,framework and design pattren
Give an example of call be reference significance.
What are the benefits of operations?
solve this is my problem byte a=40,byte b=50 both add value is 90 this is with in range of byte... byte range is -128to 127.... why this pgm gives error like type mismatch.... package javapgms; public class byte1 { public static void main(String args[]) { byte a=40,b=50; byte c=a+b; System.out.println(c); } } note : dont use int k... a,b,c are in byte range... mind it..
Can we override constructors?
what is singleton class in java?
What is data type in computer?
I have a Person object with 5 variables and I want to store them in a file called Person.txt. What should I do?