• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Returning an arrray from a method?

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
return intData[];

Try just saying "return intData". You only use the [] stuff during the declaration. The variable name does not include it.
 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic