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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:48:19+00:00 2026-05-24T23:48:19+00:00

I have two ArrayLists in java that have different sizes. ArrayLists ‘probs’ and ‘theDoubles’

  • 0

I have two ArrayLists in java that have different sizes. ArrayLists ‘probs’ and ‘theDoubles’ (sizes 4 and 5 respectively). Array ‘dprobs’ (Double[5]) is just an Array that copies the values of ‘theDoubles’.

Only those items that do not have zero-length (see ‘.size() > 0’) are allowed to be added. One of them is zero-length, and gets replaced by a ‘0.0’ double (added to the ‘theDoubles’ ArrayList).

My problem is that I do not know how to get this desired output:

i=1 j=0
i=2 j=1
i=3 j=2
i=4 j=3
    j=4

I get this instead:

i=1 j=1
i=2 j=2
i=3 j=3
i=4 j=4

Here is my code:

        for (int i = 0; i < 5; i++) {
            if (probs.get(i).size() > 0) {
                System.out.println("i: " + i);
                System.out.println("j: " + j);

                theDoubles.add(Double.parseDouble(probs.get(i).get(0).getValue()));
                dprobs[j] = theDoubles.get(j);
            } else {
                theDoubles.add(0.0);
            }
            j++;
        }
        return dprobs;

I need to display this (‘probs’ ArrayList contents):

0.0
0.0049522
0.0020487
0.0013568
0.0015332

and I am only getting this:

0.0049522
0.0020487
0.0013568
0.0015332

because ‘j’ starts at ‘1’ (it ignores the first item, which is ‘0.0’ at index 0).

Any ideas?

Thanks

  • 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-24T23:48:20+00:00Added an answer on May 24, 2026 at 11:48 pm

    It is hard to see the full picture because nothing shows where you print the second set of outputs and desired outputs. therefore i will try based on the first set that you posted: you need to increase j only when you are at an i which points to an element that is not zero length. therefore, move the j++ to your “if” block too. it becomes like this:

    for (int i = 0; i < 5; i++) {
            if (probs.get(i).size() > 0) {
                System.out.println("i: " + i);
                System.out.println("j: " + j);
    
                theDoubles.add(Double.parseDouble(probs.get(i).get(0).getValue()));
                dprobs[j] = theDoubles.get(j);
                j++;
            } else {
                theDoubles.add(0.0);
            }
    
        }
        return dprobs;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So we have a java class with two ArrayLists of generics. It looks like
I have two applications written in Java that communicate with each other using XML
I have a class that contains two arraylists which I'm trying to store objects
I have some Java code that uses curly braces in two ways // Curly
In Java, suppose I have a method that takes in two lists of integers,
Have two folders with approx. 150 java property files. In a shell script, how
I have two arrays of animals (for example). $array = array( array( 'id' =>
I'm making a shopping list mobile application (Java ME) and i have two classes;
I have a standalone Java application below that is: Generating a random line Applied
I am making a program that makes use of two Array Lists. I've researched

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.