How can I manage to return a temporary array in Java (in order to save code line, without creating a variable).
When doing initiation, I can use
int[] ret = {0,1};
While when doing return, I cannot use
return {0,1};
Do I miss something or is there a force typ-cast to do this?
I got the idea to use new int[]
as the answers below. While, what's the reason the we don't need new int[]
when doing initiation?