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

  • Home
  • SEARCH
  • 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 7727575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:29:36+00:00 2026-06-01T05:29:36+00:00

So I have this method which will take an ArrayList of Integers, I compare

  • 0

So I have this method which will take an ArrayList of Integers, I compare between 2 sub arrays and preform some swapping of numbers.

I am comparing the first elements of each sub array which is just the array halved, then swapping the elements if the bigger number isn’t in the left subList. after that I want to recursively do the same thing but to the first half.

so if I type 3 5 8 2 1 7 6 4
I want to see this;

[3, 5, 8, 2, 1, 7, 6, 4]

[3, 7, 8, 4, 1, 5, 6, 2]

[8, 7, 3, 4, 1, 5, 6, 2]

[8, 7, 3, 4, 1, 5, 6, 2]

What I want to be able to do is once I have done what I need to, to the base array, I need to work on the first half of the same array recursively. However when I compile, I get an error saying that I have incompatible types. So I’m assuming the subList function isn’t providing me a ArrayList.

Any pointers on gettign this to work correctly?

public static void tournament(ArrayList<Integer> players){
int mid = players.size()/2;
    for(int i=0; i < mid; i++){
        if(players.subList(0,mid).get(i) < players.subList(mid,players.size()).get(i)){
            int temp = players.subList(0,mid).get(i);       
            players.subList(0,mid).set(i , players.subList(mid,players.size()).get(i));
            players.subList(mid,players.size()).set(i,temp);    
        }// end if
    }// end for
    System.out.println(players);

    if(players.size() > 2){
        tournament(players);
    }// end if

}// end tournament
  • 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-01T05:29:37+00:00Added an answer on June 1, 2026 at 5:29 am

    However when I compile, I get an error saying that I have incompatible types. So I’m assuming the subList function isn’t providing me a ArrayList.

    With the Collections API (of which the ArrayList is part), the best-practice is to declare your variables using the generic interfaces: List, Set, Map, rather than their concrete implementations such as ArrayList, HashSet and HashMap.

    For example, instead of this:

    ArrayList<Integer> list = new ArrayList<Integer>();
    

    you should do this:

    List<Integer> list = new ArrayList<Integer>();
    

    If you take a look at the JavaDoc for java.util.List.subList(), you’ll see that the method signature is this:

    List<E> subList(int fromIndex, int toIndex)
    

    ArrayList, as an implementation of the List interface, uses this exact same signature. Note that the return type is List, and not ArrayList. What this means is that ArrayList.subList() doesn’t have to return you an ArrayList (although it could) – it simply has to return you an object that conforms to the List interface.

    So what is the first step? Change your method to accept a List rather than an ArrayList. (Whatever method calls your tournament() initially method can still pass an ArrayList.)

    public static void tournament(List<Integer> players)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this method which will remove all rows from a table but I
I have this method which does certain checks and applies a color code on
I have this recursive method which deletes empty folders: private void DeleteEmpty(DirectoryInfo directory) {
I have this annoying method which pop up a MessageBox. So when I try
Hi I have this method below which should insert values into my database. However
Hi I have this simple method which gets triggered when i click inside a
I have static method which plays music. How to return value from this method
I have this code: s(x => x.Open()); s is a method which calls one
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]
I need a method which will take an *.jpg image file and upload it

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.