aspose file tools*
The moose likes Beginning Java and the fly likes Returning an arrray from a method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Returning an arrray from a method?" Watch "Returning an arrray from a method?" New topic
Author

Returning an arrray from a method?

ione walker
Ranch Hand

Joined: Apr 19, 2001
Posts: 31
I have written a method (getArray) that does some stuff.
(I can't send the code as it is Cattle Drive Stuff)
it generates an array.
I can get it to sent the array to the screen using
System.out.println( intData( i ) );
But I do nto seem to be able to get the
array outside the method.
I am sure that I am doing something wrong
that is a matter of not understaning the syntax
well enough.
Cindy, I am sending you the code.
could you take out the tell-tale stuff.
Thank You Very much.
=========
(code removed by Cindy)

------------------
=======================
Ione Walker
walkeri@usa.net
========================
[This message has been edited by Cindy Glass (edited May 16, 2001).]


=======================<BR>Ione Walker<BR>walkeri@usa.net<BR>========================
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
return intData[];

Try just saying "return intData". You only use the [] stuff during the declaration. The variable name does not include it.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
This should give you some help with the syntax of arrays in methods, Ione.
Please forgive the fact that my contrived class doesn't really do anything:

In particular, notice that:
1) If a method returns an array, then the return type in the method signature has to indicate an array ("public int[] gimme() {...}").
2) In the return statement of your method, just return the name of the array: no brackets. ("return temp;", not "return temp[];").
Hope this helps, Ione.
Art
[This message has been edited by Art Metzer (edited May 16, 2001).]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Returning an arrray from a method?