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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:55:51+00:00 2026-06-12T14:55:51+00:00

I’m trying to generate arrays and calculate there values depending on some function. and

  • 0

I’m trying to generate arrays and calculate there values depending on some function. and I want to save each generated array into array List PQ.

the important methods are :
init: to initiate a series of arrays
calculate: is to calculate array measurement or value in this method I want to check if this array is already have been calculated by searching in PQ array which will have all previous calculated array.

badly, after each for stage for (j=0;j<s;j++) the sol[] object some how changed in the array list and the array list never updated with new values.

it is like there is object link between PQ.add(sol) and the calculate(solution);

how to remove this link i.e. pass-by-reference and convert it to pass-by-value so I can add new arrays to PQ Arraylist.

in another way how to pass array as value instead of reference ?
this is my code:

ArrayList previous_values=new ArrayList();
ArrayList PQ=new ArrayList();

        void init(int index) 
            {
               int j;
               for (j=0;j<s;j++)
                    {
                    r = j+1;
                    array [index][j]=r*index;
                    solution[j]=array[index][j];
                    }
                f[index]=calculate(solution);}


        double calculate(int sol[]) 
        {


            double r;
            r=search_Previous(sol);
         if(r==-1)  {


             PQ.add(sol);
    r=sol[0]*5;
previous_value.add(r);
    }
        }


        public double search_Previous(int[] arr)
            {
                double d=-1;
                for(int i=0;i<PQ.size();i++)
                {
                    if(equal_arr(arr,(int[])(PQ.get(i))))
                    {
                     return (double)previous_value.get(i) ;  
                    }
                }
                return d;
            }

        public static boolean equal_arr(int[] list1, int[] list2) {



              // Now test if every element is the same
              for (int i = 0; i < list1.length; i++) {
                  if (list1[i] != list2[i])
                      return false; // If one is wrong then they all are wrong.
              }

              // If all these tests worked, then they are identical.
              return true;
        }

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-06-12T14:55:52+00:00Added an answer on June 12, 2026 at 2:55 pm

    Hope i get you question

    .. how to pass array as value instead of reference ?
    

    You need to copy the array. Use System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into

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.