I am looking to sort my array by the name of a company, printing only the companies that are open before a specific time...... before printing
public void printCompanies(int time)
{
Iterator <Company> it = CompanyList.iterator();
while( it.hasNext()) {
Company a = it.next();
if(a.getTime() == (time)) {
Collections.sort(CompanyList.getName());
}
}
}
I am getting the error, cant find method getName(), this method is featured in another class. That is not inherited etc.
Am i on the right lines?/How would I go about fixing this error
If I use
Collections.sort(Company.getName());
then I get the error "non-static method getName() cannot be referenced from a static context?
CompanyListclass extend a Collections class and have a methodgetName(), or isgetName()a method available to individualCompanys?Comparable(and implementcompareTo()) or create aComparatorbecauseCollection.sort()can't "guess" how to sort your objects!