I am trying to sort the Project end times from smallest to largest values.
I have created a list of custom objects called Project and am attempting to sort them based on a value returned by an accessor. I have overloaded the compare function and am receiving the error:
The method sort(List, Comparator) in the type Collections is not applicable for the arguments (Project[], new Comparator(){})
The code from my main is shown below, any and all help appreciated.
Collections.sort(projectList, new Comparator< Project>(){
@Override
public int compare(Project project1, Project project2)
{
return compareProjects(project1, project2);}
}
);
public static int compareProjects(Project project1, Project project2)
{
if (project1.getEndTime() > project2.getEndTime())
return 1;
else
return 0;
}
and my Project Class:
public Project(int projectNum, int start, int end)
{
this.projectNum = projectNum;
this.start = start;
this.end = end;
this.length = end - start;
}
public static int getEndTime()
{
return end;
}