• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing a int array[][]

 
may Lee
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic