Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Obtaining and Returning an Array

Started by Xiachunyi Aug 24, 2005 at 8:45 PM 2 replies 800+ views
Original Post
Xiachunyi
Xiachunyi
Hello, I recently struck a trouble spot in which I am attempting to return an array from a public method. How would I go about doing this? I, as well, want to have an argument for a method to be able to recieve an array and manipulate/copy its contents. Pointers seem such a desirable thing to have right now. Thank you.
DRPhil
DRPhil
I hope this helps.

  public void passArray(int [] list)  {  }  public int [] returnArray()  {	int [] list = new int[10];	return list;  }
Sneftel
Sneftel
Quote:
Original post by Xiachunyi
Pointers seem such a desirable thing to have right now.

You do have pointers in Java. All Objects (including arrays) are referred to by a reference type which (other than lack of pointer arithmetic) is the same as C's pointer type. Try creating an object, passing it into a function, and modifying the object in the function; after the function returns, the modifications will have been made to the original object.
Xiachunyi
Xiachunyi
Ah I understand - it seems easy enough; much thanks to you both.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.