wood burning stoves 2.0*
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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "returning an array" Watch "returning an array" New topic
Author

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

..........java:74: incompatible types
found : double[][]
required: double
return(a);
^
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
 
Consider Paul's rocket mass heater.
 
subject: returning an array
 
Similar Threads
how to set 2d array in hidden field in java script
Returning more than one value
Returning byte array to JavaScript from Java applet
Swapping the string values in java
Jquery /Ajax returning multiple fields from servlet