• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Passing an Array of Objects

BarneyInTechno

Junior Member
hey, how would you pass an array of objects in java through the parameters? if the array was called, ver, would u jsut send it in by putting in the methodName(ver); ?

Also, how would i accept it? would i accept an array of objects the same way as an array of integers? Would it just be

public void methodName ( Objects [] blah, int size )
{
Objects []array = new Objects[size];
array = blah;
}

Is that code correct? and also if i wanted to have the array inside methodName change the one coming in through the parameters, how would id o that? thanks =)
 
I am fairly certain that it works just like it does in c/c++...

so you have a function that takes an array of Objects:

public void foo(Object bar[])
{
// some code
}

public static void main()
{
Object bar[450];
foo(bar);

return;
}

Java will pass in a reference to the Objects... so you are modifying the original set of objects, not a copy (unless you create some new objects by doing this:

bar = new Object[50];

inside the function). This is the standard behavior on ANY object or array you pass into a function... Java objects are all treated as pointers.
 
Back
Top