aspose file tools*
The moose likes Beginning Java and the fly likes passing a int array[][] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "passing a int array[][]" Watch "passing a int array[][]" New topic
Author

passing a int array[][]

may Lee
Ranch Hand

Joined: Nov 20, 2003
Posts: 68
Is the following right to passing an int array[6][300] from my servlet to a object class

This is the object class to receive the parameters from my servlet
import java.io.*;
public class data implements Serializable{
public boolean a;
public int[][] b;
public data(boolean arg1,int[][] arg2){
a=arg1;
b=arg2;
}

my servlet will do something then get an array d and boolean:
data c;
int[][] d;
boolean e=flase;
d=new int[6][300];
...

c=new data(e,d);

Is this possible to pass array d obtained in my servlet to the data class c?
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
hi may, yes you can pass the array, however, you pass only the reference. So you might want to copy the array into a new one in the data class.

hope that helps.

ben
may Lee
Ranch Hand

Joined: Nov 20, 2003
Posts: 68
What do you mean copy a new one?could you show me by example?
I also read that if I only pass the reference, in fact the array in the data class doesn't get the values. I don't want this.
Ben Buchli
Ranch Hand

Joined: Mar 26, 2004
Posts: 83
I dont know if you already resolved your issue, but if not, here some more help:

when you pass your Array to the data class constructor, you only pass the reference to that particular array. So, there's only one array, which might be changed from either your servlet or the data class. That's why you want to copy the array into a new one. You do that by using a loop:



of course you gotta take care of your 2-dimensional array... but works similarly.

hope that helps
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing a int array[][]