Android Function to return an array directly into variables
10,308
This is a rather basic question: Anyway :
public int[] foo() {
int i = 0;
int j = 0;
int k = 0;
return new int[]{i,j,k};
}
Author by
ilomambo
I have a solid programming education. Trying to learn how everything works and interacts. Hopefully, to write great applications.
Updated on June 13, 2022Comments
-
ilomambo almost 2 years
I saw that javascript has something similar.
Is it possible to do something like this in Android? I know how to do it with array names, my question is about returning and assigning directly from the variables that compose the arrays.private int[] calcHead() { int i; int j; int k; // Do stuff return {i, j, k}; <-- is this possible? (I am getting error: "The Method must return a result of type int[]") } private void otherFunc(){ int a; int b; int c; {a, b, c} = calcHead(); <-- is this possible? }
-
ilomambo almost 12 yearsThank you, silly questions are the most difficult to google. Please can you answer the other half of the question (the assignment to multiple variables at once), so I credit you with the answer?
-
Sherif elKhatib almost 12 yearsI did not mean as an insult to you. I answered. Can you please explain the "other half"?
-
ilomambo almost 12 yearsNo insult taken! This forum is sometimes for silly questions too, if you cannot find the answer reasonably fast by searching yourself. The other half is: can I do something like {a,b,c} = calcHead( ), see in the question body
-
Sherif elKhatib almost 12 yearsunfortunately the other part is not doable ):