Next: List, Previous: Collection, Up: Classes [Index]
Array
ClassThe Array
class contains objects ordered by index from
0... n.
Instances of Array
objects store unique copies of objects,
so they can be added and deleted without worrying too much if
an Array
member is referred to by another object (unless
the program later refers to the Array
member; i.e., after
it’s been stored with a method like atPut
).
So most statements on Array
members are safe, but you should be
careful when using multiple Array
operations in the same
expression. For example, the following expression is not safe.
myArray atPut 0, ((myArray at 0) - 3);
That’s because the atPut
method replaces the element at 0 while
the original element is still being used as an argument. It’s safer
to use another object to work on an Array
element.
tmpInt = ((myArray at 0) - 3); myArray atPut 0, tmpInt;
value
The value is the name of the array.
0... n
These instance variables refer to the elements of the array.
=
(Array
a)
Set the receiver array’s elements equal to the argument array’s elements.
asString
(void
)
Returns the contents of the receiver Array
as a String
object. If any member of the receiver is a Character
object,
unquotes the Character
object’s value and concatenates the
character to the result string. Otherwise the method concatenates
each of the receiver Array
’s values into the result string.
at
(int
n)
Retrieve the nth element of the receiver array.
atPut
(int
index, OBJECT *
item)
Add item to the receiver at index.
map
(method)
Executes method with each element of the receiver.
The argument, method, is a method that should belong to the same
class as the receiver. When method is executed, its receiver is
each successive array element, and method can refer to it with
self.
size
(void
)
Return the number of elements in the receiver.
Next: List, Previous: Collection, Up: Classes [Index]