File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Passing an Array into a Method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing an Array into a Method" Watch "Passing an Array into a Method" New topic

Passing an Array into a Method

Landon Blake
Ranch Hand

Joined: Dec 04, 2003
Posts: 121
I need to pass an array as an argument to a method, and I'm not sure how to code it. Does it go something like this:
private void methodName (array arrayName);
private void hungryMonster (array slimyThings);

Do I need to specify the data type of the array in the argument to the method? Or is this not a concern since the data type of the array was defined when it was created?
Also, is there a way to "import" an array into an object so it's values can be accessed just like the object's member varaibles?
Thanks for any help,
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
general format is
private void methodName (arrayType arrayReference) {}
arrayType : could be int[], String[][],.. that indeicates the parameter is array
arrayReference : arrayName.
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Here's an example posted yesterday
JavaRanch link
I agree. Here's the link:
subject: Passing an Array into a Method
It's not a secret anymore!