File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes returning an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "returning an array" Watch "returning an array" New topic

returning an array

Kevin Knowles
Ranch Hand

Joined: Dec 29, 2002
Posts: 45
How do I return an array?
Is it
return (a[][]);
or is it
return (a);
Blake Minghelli
Ranch Hand

Joined: Sep 13, 2002
Posts: 331
use return a;
You use the backets only when declaring an array (e.g. String a[][] = new String[5][5]) or working with a specific element in an array (e.g. a[1][2] = "test" or String s = a[1][2]).
When in doubt, just try compiling it.

Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Kevin Knowles
Ranch Hand

Joined: Dec 29, 2002
Posts: 45
Well, thanks, but I get this errror
when using
return (a); incompatible types
found : double[][]
required: double
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
What are you declaring that you return? You need to do something like this:
public double[][] myMethod() {
double[][] a;
return a;
And when you invoke the method:
double[][] b = myMethod();

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: returning an array
It's not a secret anymore!