I want to store the array returned by a method into another array. How can I do this?
public int[] method(){
int z[] = {1,2,3,5};
return z;
}
When I call this method, how can I store the returned array (z) into another array?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The above method does not return an array par se, instead it returns a reference to the array. In the calling function you can collect this return value in another reference like:
After this
copywill also refer to the same array thatzwas refering to before.If this is not what you want and you want to create a copy of the array you can create a copy using
System.arraycopy.