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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:07:34+00:00 2026-06-13T23:07:34+00:00

I have a list of points. I represented this as an ArrayList of ArrayLists.

  • 0

I have a list of points. I represented this as an ArrayList of ArrayLists. I’m trying to use generics so that the list can store Integers, Floats, etc. and treat them the same. So I have:

ArrayList<ArrayList<? extends Number>>. 

I need to compare these lists based on one element in each inner list.

So to do that I wrote a custom Comparator that I’m using in Collections.sort

The Comparator looks like:

int compare(ArrayList<? extends Number> a, ArrayList<? extends Number> b )
{
    return a.get(index).compareTo(b.get(index))
}

This doesn’t compile of course. The compiler complains that there is no compareTo method for the wildcard class.

Is what I’m trying to do even possible?

  • 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-13T23:07:34+00:00Added an answer on June 13, 2026 at 11:07 pm

    How about defining your Comparator class as:

    class MyComparator<T extends Number & Comparable<T>> 
                                              implements Comparator<ArrayList<T>> {
        @Override
        public int compare(ArrayList<T> a, ArrayList<T> b) {
            return a.get(index).compareTo(b.get(index));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a std::list of Points (that simply store an x, y). Each one
I have a list of data points (0.2, 0.8, 0.95) that I want to
I have a SharePoint external list that points to a 100,000 record SQL table.
I have a ViewModel class that contains a list of points, and I am
In Scala I have a list of objects that represent points and contain x
This is related to this question I have a vector of points that will,
I have a list of objects (L1) and another list of integers (L2) that
I have a list of points as shown below points=[ [x0,y0,v0], [x1,y1,v1], [x2,y2,v2].......... [xn,yn,vn]]
I have a list of points moving in two dimensions ( x - and
I have two polygons which are defined by a list of points: x1,y1; x2,y2;

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.