• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

passing a int array[][]

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic