Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing values

 
Grant Allen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i pass a value from a method into an array, the value = length of array;
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand either If you could explain a bit more.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48981
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic