Java error :- "no suitable method found for sort(Student[],j)"

Java error :- "no suitable method found for sort(Student[],j)"

大家好,我是 java 编程的新手,在练习时遇到错误,请帮助我解决上面提到的问题(标题)。我也在这里附上我的代码,请解决这个问题并提前致谢:)

代码:

import java.util.Collections;
import java.util.Comparator;
class Student{
    public int marks;
    public String name;
    public Student(int marks, String name){
        this.marks = marks;
        this.name = name;
    }
    @Override
    public String toString(){
        return ("Name: " + this.name + " Marks: " + this.marks);
    }
}
public class j implements Comparator<Student>{
    @Override
    public int compare(Student o1, Student o2){
        if (o1.marks < o2.marks)
            return 1;
        else
            return -1;
    }
    public static void main(String[] args) {
        Student[] array = new Student[2];
        array[0] = new Student(10, "varun");
        array[1] = new Student(20, "gupta");
        Collections.sort(array, new j());
        for (Student i : array)
            System.out.println(i);
    }
}

你应该改变 Collections.sort(array, new j());到 Arrays.sort(array, new j());