我必须按日期和时间订购约会.我有一个约会的ArrayList,并试图创建一个比较器来比较他们的日期和时间.我正在尝试使用Collections.sort方法,将其传递给Appointments的ArrayList和我创建的AppointmentComparator.在编译时,我得到了“没有合适的排序方法”.这是编译器生成的完整错误消息的链接:http://prntscr.com/7y4qb
比较:
public class AppointmentComparator implements Comparator
带语法错误的行:
Collections.sort(book,new AppointmentComparator());
变量book是约会的ArrayList.的ArrayList<预约>
预约书类:
import java.util.ArrayList;
import java.util.Collections;
public class AppointmentBook
{
private ArrayList
预约课程:
public class Appointment
{
private String desc;
private int day; //in format mmddyyyy
private int start; //in format hhmm
private int end; //in format hhmm
public Appointment(String description,int aptDay,int startTime,int endTime)
{
desc = description;
day = aptDay;
start = startTime;
end = endTime;
}
public String getDescription()
{
return desc;
}
public int getDay()
{
return day;
}
public int getStart()
{
return start;
}
public int getEnd()
{
return end;
}
}
最佳答案
原文链接:https://www.f2er.com/java/438063.html