Two Laptop Bag*
The moose likes Beginning Java and the fly likes Collections sort statement not being accepted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Collections sort statement not being accepted" Watch "Collections sort statement not being accepted" New topic
Author

Collections sort statement not being accepted

Armando Moncada
Ranch Hand

Joined: Nov 14, 2011
Posts: 30

The Eclipse editor won't accept the line where I am trying to sort the array list using my custom comparator. (It is the second to the list line of code). Eclipse says
The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (ArrayList<String>, SortNames.CelebrityNamesFile.CompareLastName).

The purpose of the program is to read names from a text file, add them to an array list, sort the array list in natural order, then print it, sort the arraylist by last name, then print it again.

I have read the pertinent chapters in Just Java, Ivor Horton's Beginning Java 7, Head First Java, Googled, StartPaged, and Binged the internet for examples but I still don't know what it wants.


Armando
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

First take the error ...

The method sort(List<T>, Comparator<? super T>) in the type Collections is not applicable for the arguments (ArrayList<String>, SortNames.CelebrityNamesFile.CompareLastName).


then try to prove the compiler wrong, by finding a type for T that will work.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Collections sort statement not being accepted
 
Similar Threads
How to "flip" an array?
determine the input type of the value of the function parameter map
Collection sort
Sorting through Comparable(Very Urgent)
While-loop , can't BREAK