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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:20:18+00:00 2026-06-04T03:20:18+00:00

I want to create a class that exends Comparator. This comparator will compare two

  • 0

I want to create a class that exends Comparator. This comparator will compare two arrays, where the arrays can contain anything that is comparable. Something that would let me do things like this:

comparator.compare(new Integer[] {1,2}, new Integer[] {3,4,5});

the type of the parameters are not necessarily Integer[]. They could be an array of anything.

Is there any way I can create such a class using generics? Or should my comparator receive objects instead. If it must receive objects, how can I check if it is an array and get elements from inside it?

  • 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-04T03:20:20+00:00Added an answer on June 4, 2026 at 3:20 am

    How about using the array itself as the type parameter to Comparator?

    public class ArrayComparator<T extends Comparable<? super T>> implements
            Comparator<T[]> {
        @Override
        public int compare(T[] o1, T[] o2) {
            // TODO
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to create a class that initializes a timer which will be used
If I create a class that extends UserControl and want to set a default
I want to create whois class like that public class DomainInfo { public string
So I want to create my own Azure Table class that uses only IronPython
I want to create a substr method in C++ in a string class that
Suppose I’m making an Objective-C class that represents a fraction, and want to create
I want to create a list of class instances that automatically updates itself following
I have create my own NSOpenGLView class, right now the data that i want
I want to create an anonymous inner class that extends another class. What I
I have class that extends AsyncTask class and I create instance of this class

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.