2 개의 정수와 1 개의 문자열을 포함하는 3 개의 객체를 정렬해야합니다. 내 질문은 Java에 익숙하지 않았기 때문에 어떻게 객체에 메소드를 호출 할 수 있습니까? 이것이 내 코드입니다. 멀리 : 그래서 내가하려는 것은 나이, 이름, 일반 급료에 따라 모든 3 개의 객체를 정렬하는 것입니다. 어떻게 정렬 할 수 있도록 모든 객체를 호출 할 수 있습니까? 아니면 내가 잘못하고있는 경우, 대체 뭐야? 나는 List와 3 개의 객체를 사용할 필요가있다.정수와 문자열의 정렬 목록 Java
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
public class Student {
int age;
int generalGrade;
String firstName;
String lastName;
public Student(int age, String firstName, String lastName, int generalGrade) {
this.age = age;
this.generalGrade = generalGrade;
this.firstName = firstName;
this.lastName = lastName;
}
public static void main (String[] args) {
Student myStudent = new Student(19, "A", "X", 100);
Student myStudent1 = new Student(20, "B", "P", 98);
Student myStudent2 = new Student(19, "C", "N", 70);
Age(myStudent);
}
public void Age(int[] age) {
List studentAge = new ArrayList(Arrays.asList(age));
System.out.println("List values before sort " + studentAge);
Collections.sort(studentAge);
System.out.println("List value after sort: " + studentAge);
}}
사용자 지정 비교기를 작성한 다음 해당 비교기를 사용하여 Collections.sort를 작성하십시오. – Sanjeev