Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I return an array of objects in java?

Tags:

java

How do I return an array of objects in java?

like image 665
shil Avatar asked Apr 01 '10 05:04

shil


1 Answers

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.)

like image 180
Jon Skeet Avatar answered Oct 19 '22 23:10

Jon Skeet