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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:08:30+00:00 2026-06-08T07:08:30+00:00

I am working on a programming assignment and I could use some help understanding

  • 0

I am working on a programming assignment and I could use some help understanding the compareTo method.

One of the questions of the assignment is to add an incoming element to a list. If the list is sorted, I am supposed to put the new node in its correct position. The list can be either sorted in an ascending or descending order. I thought I could check which is the order by comparing the head node to the node after (node.getNext()) but I am not sure. The line of code that I am not sure on is the following:

if(head.getContent().compareTo(tp.getContent())==1)

head is the first node is a generic data type T, which has already been added. tp is head.getNext() just to save space and is also a generic data type T, since I am sure I will be typing it again. I did not write a compareTo method on the program because the professor told me that simply call the compareTo method to compare another generic data type. Also, I am not sure on the difference between:

extends Comparable<T>

and

implements Comparable<T>

but the assignment requires me to use the first one.

if the head node element is 1 and the next on is 3, what will the output of the if statement be? true or false?

  • 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-08T07:08:32+00:00Added an answer on June 8, 2026 at 7:08 am

    Basically the way to think of compareTo is to ALWAYS put a zero on the other side of it and then imagine that the operator is between the two arguments.

    A.compareTo(B) == 0; // A == B
    A.compareTo(B) > 0; // A > B
    A.compareTo(B) >= 0; // A >= B
    
    //etc etc etc
    

    This makes it much easier to read and saves you trying to figure out what you actually meant by >-1 or something in two years

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

Sidebar

Related Questions

I'm working on an assignment for my programming class but I've run into some
I'm working on assignment 2 of CS193P - Stanford's IOS programming course. One thing
I'm working on my first programming assignment for Java and I had another question.
I am working on some review material for dynamic programming. I need to come
I'm working through the Stanford iPhone programming course online. The Presence app assignment pulls
I'm in the process of working on programming project that involves some pretty extensive
I'm working on a programming assignment, to make a function template that can handle
I'm working on C programming assignment to implement Sieve of Eratosthenes without using the
I am doing a c programming assignment where I am working with command-line arguments.
I am working on an assignment for my GUI programming class, in which we

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.