0
我有这种方法可以通过变量id对对象数组进行排序,还有名称& GPA。你将如何去排序整个对象的数组?我只得到ID的排序,但输出时的名称是混合的。这是我迄今为止所做的。按多个条件对数组进行排序
private Student[] st;
private int count;
public ProcessStudents() {
st = new Student[5];
count = 0;
public void sortAscendingID() {
for (int n = 0; n < count - 1; n++) {
int min = st[n].getId();
int index = n;
for (int o = n + 1; o < count; o++) {
if (st[o].getId() < min) {
min = st[o].getId();
index = o;
}
}
if (st[n].getId() > min) {
int p = st[n].getId();
st[n].setId(min);
st[index].setId(p);
}
}
}
}