• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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
[email protected]
========================
[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).]
 
Hold that thought. Tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic