how comparetor works in java ?
import java.util.*;
public class S {
static Scanner sc = new Scanner(System.in);
static Integer a[] = new Integer[3];
public static void main(String[] args) {
int t = sc.nextInt();
while (t-- > 0) {
int n=3;
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a,new Sort1());
}
}
}
class Sort1 implements Comparator<Integer>
{
public int compare(Integer a,Integer b)
{
for(int a1:S.a){
System.out.print(a1+" ");
}
System.out.println();
// return a-b;
return 1;
}
}
Input:
1
5 2 7
output
5 2 7
why output is not 7 5 2?
what am I think if we return 1 than.
1.5
2.5 2(becuse of one return)=>2 5
3.7 2 5=>7 5 2
In brief I am curious about how internal values are compare and sorting is done.