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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:46:19+00:00 2026-05-23T08:46:19+00:00

Suppose you have two arrayLists: A and B. How do I create a new

  • 0

Suppose you have two arrayLists: A and B.

How do I create a new array which is the same size as B and stores the index values of A as integers in sequential order.

So say for example the size of B is 5 and A has 3 values.

A[0] = Ra
A[1] = Be
A[2] = Ce


B[0] = F
B[1] = M
B[2] = K
B[3] = P
B[4] = L

I want to then create in java different possible versions (say 5 versions) of an arrayC of size 5 (the same size as listB) with a sequential ordering of the indexes of listA.

So like:

arrayC[0] = 0
arrayC[1] = 1
arrayC[2] = 1
arrayC[3] = 2
arrayC[4] = 2

or

arrayC[0] = 0
arrayC[1] = 0
arrayC[2] = 1
arrayC[3] = 2
arrayC[4] = 2

are both valid combinations in arrayC. However

arrayC[0] = 0
arrayC[1] = 2
arrayC[2] = 1
arrayC[3] = 2
arrayC[4] = 2

is not.

  • 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-05-23T08:46:20+00:00Added an answer on May 23, 2026 at 8:46 am

    This method returns all orderings. Limit it if you just want a few.

    public static Set<List<Integer>> orderings(int i, int len, int max) {
    
        Set<List<Integer>> seqs = new HashSet<List<Integer>>();
    
        if (len <= 0 || i > max)
            return seqs;
    
        if (max - i == len) {
            List<Integer> l = new ArrayList<Integer>();
            while (i < max)
                l.add(i++);
            seqs.add(l);
            return seqs;
        }
    
        seqs.addAll(orderings(i    , len - 1, max));
        seqs.addAll(orderings(i + 1, len - 1, max));
    
        for (List<Integer> l : seqs)
            l.add(0, i);
    
        return seqs;
    }
    
    
    public static Set<List<Integer>> orderings(int[] arr1, int[] arr2) {
        return orderings(0, arr2.length, arr1.length);
    }
    

    Test code:

    public static void main(String[] args) {
        int[] listA = { 0, 1, 2 };
        int[] listB = { 0, 1, 2, 3, 4 };
        for (List<Integer> seq : orderings(listA, listB))
            System.out.println(seq);
    }
    

    Output:

    [0, 0, 1, 2, 2]  <-- your second example
    [0, 1, 1, 1, 2]
    [0, 1, 1, 2, 2]  <-- your first example
    [0, 1, 2, 2, 2]
    [0, 0, 0, 1, 2]
    [0, 0, 1, 1, 2]
    

    Ideone.com demo:
    Link

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

Sidebar

Related Questions

Suppose I have two classes with the same interface: interface ISomeInterface { int foo{get;
suppose that you have two activities A(which is the main activity) and B when
Suppose you have two tables in PostgreSQL. Table A has field x , which
Suppose I have two columns, keywords and content. I have a fulltext index across
Suppose you have two datetime values, date_a and date_b What expression evaluates to true
Suppose I have two methods bool Foo() and bool Bar() . Which of the
suppose I have two columns of integers, A and B. Now I want distinct
In Java, suppose I have a method that takes in two lists of integers,
Suppose I have two url for the same file, say http://site.com/fr/page.php and http://site.com/en/page.php .
Suppose I have two lists, and corresponding elements of the lists are the same

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.