Hi. I got a noobish question:

Is it possible to return an array "directly", so, something like this.

public int[] getArray(){

return int[]{this.intA, this.intB};


I know I can just make the array first. But does this not use unnecessary cpu time and memory? This is going to be used a lot, so performance is the most important element here.


Is it possible to return an array "directly",

Have you tried it with the compiler? Do you get errors?

Yes. I can't seem to find a legal way of doing this.

sample code:

public int[] retInt() {
  return new int[}{1};

Ohh, yeah. Right ^^. Lol, I accually knew that when you mentioned it. Thank you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.