0

I am trying to sort a linked list and keep getting "no suitable method found for sort(LinkedList,>). What am I doing wrong?

public Contributor(String firstName, String lastName, String city,
            String country, String phone, double contribution, int id) {
        // CONSTRUCTOR WITH ALL ATTRIBUTES PASSED
        this.firstName = firstName;
        this.lastName = lastName;
        this.country = country;
        this.phone = phone;
        this.contribution = contribution;
        this.id = id;
    }

public static LinkedList<Contributor> contributorList = new LinkedList<>();



Collections.sort(contributorList, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Collator.getInstance().compare(o1, o2);
            }
        });
4
  • 1
    What type is contributorList? Commented Jul 27, 2015 at 18:21
  • Can we see the declaration of contributorList? Commented Jul 27, 2015 at 18:21
  • 2
    Then you should have Comparator<Contributor>. Commented Jul 27, 2015 at 18:23
  • pls post Contributor class. attribute you want to sort Commented Jul 27, 2015 at 18:23

1 Answer 1

2

Sort using comparator by comparing Contributor objects.

Collections.sort(contributorList, new Comparator<Contributor>() {
    @Override
    public int compare(Contributor o1, Contributor o2) {
       return Collator.getInstance().compare(o1.lastname, o2.lastname);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.