Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing an array in a method call 1

Status
Not open for further replies.

fortuneman

Technical User
Oct 27, 2000
10
US
I don't know if my question was properly worded. Basically I have a created method called addMultiple and it's expected arguments are:

public void addMultiple(int index, Object[] theElements)

Passing the integer is fine but I'm having trouble passing the array expected as the second argument.
 
basically what do I put in for the ???.

x.addMultiple(1, ???);
 
Maybe if you tell us what are you trying to pass as parameter ...

Cheers.

Dian.
 
Integer[] i = new Integer[2];
i[0] = new Integer(555);
i[1] = new Integer(888);
x.addMultiple(1, i);

or

x.addMultiple(1, new Integer[]{ new Integer(555), new Integer(888)});

or any other array of objects you require ...
 
That did it sedj thanks alot. I keep forgetting that java is soooo strictly typed. I was assuming it knew the digits in the new Integer[] array were integers. I didn't define each one as an integer. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top