Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:33:05+00:00 2026-06-13T12:33:05+00:00

I created my own LinkedList class that can take in objects specified with a

  • 0

I created my own “LinkedList” class that can take in objects specified with a generic.

In that Class, I want to have a sort(ComparatorObject) method that takes in an object whose Class implements Comparator.

The reason for that is that for my test objects in particular, Shapes, I want to see if I can sort them by various fields selected by the user, such as the shapes’ areas, perimeter, type, etc.

Right now, one of my comparator classes is defined like this:

public class Comparator_Area implements Comparator<Shape>{

@Override
public int compare(Shape shape1, Shape shape2) {
    int valueToReturn = 0;

    if(shape1.getArea() < shape2.getArea()){
        valueToReturn = -1;
    }
    else if(shape1.getArea() < shape2.getArea()){
        valueToReturn = 1;
    }

    return valueToReturn;
}
}

And in my LinkedList Class, my sort method is defined like this (I don’t know if it’s correct, but it’s what I found while looking up how to do this):

public void sort(Class<? extends Comparator<E>> comparator){

}

Naturally, I’d like to be able to use something like this in the sort method:

comparator.compare(shape1, shape2);

But I can’t use “compare” and I don’t really know how I’m supposed to accomplish this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:33:06+00:00Added an answer on June 13, 2026 at 12:33 pm

    You should send a Comparator object as parameter in your sort method:

    public void sort(Comparator<Shape> comparator){
    
    }
    

    This is assuming your LinkedList class is only of Shapes. If you have a generic LinkedList implementation, then you can pass a Comparator<T>:

    public class MyLinkedList<T> {
        //other methods...
    
        public void sort(Comparator<T> comparator){
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my own custom LinkedList class that has a pointer to the first
I have created my own Attached Property like this: public static class LabelExtension {
I have created two classes, class A that uses a Linked List and class
I have created my own custom Linked List (code is below). Now, I can't
I created my own music player that runs on iPhone using the class MPMusicPlayerController
I created my own MyScrollbarUI class to have a custom scrollbar look in my
I created my own class but when I try to instantiate it I run
I created my own behavior as follows: public class BoundaryExceptionHandlingBehavior : IInterceptionBehavior { public
I've created my own signup form and creating the user using the Membership class.
I have created my own customized lots of architecture including n-tier layers for different

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.