How do I return an array of objects in java?
Well, you can only actually return an array of references to objects - no expressions in Java actually evaluate to objects themselves. Having said that, returning an array of Object references is easy:
public Object[] yourMethod()
{
Object[] array = new Object[10];
// Fill array
return array;
}
(To be utterly pedantic about it, you're returning a reference to an array of object references.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With