Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing an Array into a Method

 
Landon Blake
Ranch Hand
Posts: 121
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
Example:
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,
Landon
 
chi Lin
Ranch Hand
Posts: 348
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
general format is
private void methodName (arrayType arrayReference) {}
arrayType : could be int[], String[][],.. that indeicates the parameter is array
arrayReference : arrayName.
HTH
 
Michael Dunn
Ranch Hand
Posts: 4632
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's an example posted yesterday
JavaRanch link
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic