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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:15:54+00:00 2026-05-22T16:15:54+00:00

On the following code: static void findSubsets (ArrayList<Integer> numbers, int amount, int index) {

  • 0

On the following code:

static void findSubsets (ArrayList<Integer> numbers, int amount, int index)
{
    ArrayList <Integer> numbersCopy = new ArrayList<Integer>(numbers.size());
    Collections.copy(numbersCopy, numbers);
}

I’m getting the error:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Source does not fit in dest
        at java.util.Collections.copy(Collections.java:548)
        at backtracking2.Main.findSubsets(Main.java:61)

Why?

  • 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-22T16:15:54+00:00Added an answer on May 22, 2026 at 4:15 pm

    Capacity does not equal size. The size parameter that you are passing in simply allocates enough memory for the size. It does not actually define elements. It’s actually kind of a silly requirement of Collections.copy, but it is one nonetheless.

    The key part from the Collections.copy JavaDocs:

    The destination list must be at least as long as the source list. If it is longer, the remaining elements in the destination list are unaffected.

    You should just pass the List to the ArrayList‘s constructor to copy all of the List to avoid the issue altogether.

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

Sidebar

Related Questions

The following code public static void main(String[] args) { fun(new Integer(1)); } static void
I have the following code: class Program { static void Main(string[] args) { new
Considering following code public class A { public static void main(String[] args) { new
Consider the following code: class Program { static void Main(string[] args) { new Program().Run(args);
Consider the following code: static void Main(string[] args) { using (MemoryStream memoryStream = new
I have the following code: static ArrayList<PreparedStatement> alPrepStmts = new ArrayList<PreparedStatement>(); static PreparedStatement m_stmtOne;
i have the following code public static void main(String[] args) { int x=0; int
I want to simplify the following code: public static void main(String[] args) { int
I create a new thread that runs the following code: public static void startServer()
I have the following code: public static void main(String[] args) { try { int

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.