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 8726921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:20:37+00:00 2026-06-13T08:20:37+00:00

How can I compare two ListNode values to return 1 if ListNode o1.value >

  • 0

How can I compare two ListNode values to return 1 if ListNode o1.value > ListNode o2.value, return 0 if equal, and return -1 if less than.

I have this comparator right now but there is an error saying that abstract methods are not implemented. Also, I’m unsure if they will compare correctly for values such as the example below.

Add ‘d’. add ‘b’. add ‘e’

b->d->e

private Comparator<? super E> priorityComparator = new Comparator<E>(){ 
  public int compare(ListNode<E> o1, ListNode<E> o2) {
     String i1 = o1.value.toString();
     String i2 = o2.value.toString();
        return i1.compareTo(i2);
    }};

How can I implement this comparator correctly so that it takes two ListNode objects and returns the int value comparison between them?

  • 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-13T08:20:38+00:00Added an answer on June 13, 2026 at 8:20 am

    You’ve currently not implemented Comparator<E>.compare – you’ve implemented Comparator<ListNode<E>>.compare. You either need to change the type of your variable, or you need to change the parameters to the method. If you really want to make something which compares nodes, then you want Comparator<ListNode<E>>.

    Also note that your comparison only really works for types where toString() is overridden in a manner which is compatible with its natural ordering. For example, it wouldn’t work well with ListNode<Integer>, as it would claim that a value of 10 was less than a value of 2…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a gem that can compare two strings (in this case
How can I compare two NSMutableArray ? if both are same than it should
How can I compare two NSDates and return the amount of time between them.
How can i compare two collections in backbone? I have two collection 1C contains
How can I compare two values without using IF. I know it´s possible to
Possible Duplicate: How can I compare two dates, return a number of days I
I have a two same tables.Database mysql. How can I compare two tables? Table1,Table2
Can anyone suggest a Perl module which can compare two strings and return a
Does Python have any standard lib which can compare two files by omitting the
How can I compare two NSArray s and put equal objects into a new

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.