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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:00:44+00:00 2026-06-11T02:00:44+00:00

I am having a problem with one of my methods in my program. The

  • 0

I am having a problem with one of my methods in my program. The method is designed to take 2 arraylists and the perform multiplication between the two like a polynomial.

For example, if I was to say list1={3,2,1} and list2={5,6,7}; I am trying to get a return value of 15,28,38,20,7. However, all I can get is an error message that says:

Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 0, Size: 0.

I have provided the method below:

private static ArrayList<Integer> multiply(ArrayList<Integer> list1,ArrayList<Integer> list2) {

    ArrayList<Integer> array =new ArrayList<Integer>(list1.size()+list2.size());

    for (int i=0;i<array.size();i++)
        array.add(i, 0);

    for (int i = 0; i < list1.size(); i++)

        for (int j = 0; j < list2.size(); j++)

            array.set(i+j, ((list1.get(i) * list2.get(j))+array.get(i+j)));

    return array;

}

Any help with solving this problem is greatly appreciated.

  • 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-11T02:00:46+00:00Added an answer on June 11, 2026 at 2:00 am

    Change your first for loop to:

    for (int i = 0 ; i < list1.size() + list2.size() ; i++)
        array.add(0);
    

    As you have it, array.size() is initially 0 so that first for loop is never even entered, so nothing is being added to array. An ArrayList‘s capacity is not the same thing as its size.

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

Sidebar

Related Questions

I am having a problem like this one: http://svn.haxx.se/tsvnusers/archive-2008-07/1051.shtml Except that the app is
So i'm having this problem. I have two tables (Oracle), one is called Destination
I am having problem with ViewDidLoad Method.I have one .Xib File in my app
I'm having this weird problem: when my program reach this method: //Returns the transpose
I am having one problem with the PHP json_encode function. It encodes numbers as
I'm having a problem with one of my functions within a template class. template
hi forum member I am having one problem with setting the radiofield in the
I'm creating shopping cart and I'm having one problem: When someone orders an item
I'm very new to Python development, and am having a problem with one of
I'm having a problem with ASP.Net mysteriously losing one of my QueryString parameters. I

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.