File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes passing values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "passing values" Watch "passing values" New topic
Author

passing values

Grant Allen
Greenhorn

Joined: Jun 04, 2006
Posts: 8
how can i pass a value from a method into an array, the value = length of array;
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Grant Allen:
how can i pass a value from a method into an array, the value = length of array;

Assuming that the method returns a type consistent with what the array holds, you can assign a method's return value to an array like this...

myArray[x] = myMethod();

I'm not sure I understand what you mean by "the value = length of array," but if the array is declared to hold int values, you could certainly do this...

myArray[x] = myArray.length;


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I don't understand either If you could explain a bit more.


[My Blog]
All roads lead to JavaRanch
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
You can have an array:-You can pass the array as an argument to a method.
You can get the method to return an array.
You can pass a number and get a method to produce an array that size.
You can get the length attribute of any array, which is a common-or-garden int number, and pass it as an argument. You name it, you can do it.

You use [] when you are creating the array, or referring to a aprticular member.

If you are referring to a whole array, you miss out the [].

CR
[ June 05, 2006: Message edited by: Campbell Ritchie ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: passing values