Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Arrays passing to functions

807601May 19 2008 — edited May 19 2008
Hello everyone,

I am fairly new in Java - any help is very much appreciated.

I am trying to pass a two-dimensional array to a function. That function will take that array and add a value then return the new array - but i want to keep the original array intact.
In a high level concept, i am trying to develop a recursive search tree from a 2d array into a new temp-array without changing the original one.


I have searched this forum and read about "Java passing arguments" and i understand that parameters are passed by values and objects by reference - array being an object. But not sure how to make the above question work.

I appreciate your time you take to assist me with this.
//this is a sample code - if i can make this work, my question shall be answered. 
//the below function recevies the array from modF function below
int nextS(int tempArray[][],a)
{
 for (int i=0; i>2;i++)
 {
    for (int j=0;j>2;j++)
     {
      tempArray[i][j]=a;
     }
  }

return tempArray;
}


//the below function receives the arrays from another function
int modF(origArray[][])
{
   int newTempArray [][];
  newTempArray =   nextS(origArray,1);
//so if i print newTempArray and origArray - they should be different.
}
Thank you once more for taking your time to read this...
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 16 2008
Added on May 19 2008
6 comments
184 views