PATH |
NSMutableArray
- Inherits from:
- NSArray
- Package:
- com.webobjects.foundation
Class Description
The NSMutableArray defines the programmatic interface for managing collections of objects called arrays. It adds insertion and deletion operations to the basic array-handling behavior inherited from its superclass, NSArray.
Table 0-7 describes the NSMutableArray methods that provide the basis for all NSMutableArray's other methods; that is, all other methods are implemented in terms of these. If you create a subclass of NSMutableArray, you need only ensure that these base methods work properly. Having done so, you can be sure that all your subclass's inherited methods operate properly.
Method | Description |
addObject | Adds an object to the array. |
addObjects | Adds multiple objects to the array. |
insertObjectAtIndex | Inserts an object into the array at a specified index. |
removeAllObjects | Empties the receiver of all its elements. |
removeObjectAtIndex | Removes the object at a specified index from the array. |
replaceObjectAtIndex(Object, int) |
Replaces the object at a specified index with another object. |
setArray | Sets an array's elements to the ones in another array. |
sortUsingComparator | Sorts the elements of the array. |
The other methods provide convenient ways of inserting an object into a specific slot in the array and removing an object based on its identity or position in the array.
Method Types
- Creating mutable arrays
- NSMutableArray
- immutableClone
- clone
- Adding and replacing objects
- addObject
- addObjects
- addObjectsFromArray
- insertObjectAtIndex
- replaceObjectAtIndex
- replaceObjectsInRange
- setArray
- Removing objects
- removeAllObjects
- removeIdenticalObject
- removeLastObject
- removeObject
- removeObjectAtIndex
- removeObjects
- removeObjectsInArray
- removeObjectsInRange
- Rearranging objects
- sortUsingComparator
Constructors
NSMutableArray
public NSMutableArray()
Creates an empty mutable array.
public NSMutableArray(int capacity)
public NSMutableArray(NSArray anArray)
public NSMutableArray(Object anObject)
public NSMutableArray(Object[] objects)
public NSMutableArray( Object[] objects, NSRange aRange)
public NSMutableArray( java.util.Vector aVector, NSRange aRange, boolean checkForNull)
null
value in the vector: if checkForNull is true
, the null value is simply ignored. If checkForNull is false, the method raises an IllegalArgumentException.
Instance Methods
addObject
public void addObject(Object anObject)
null
, an IllegalArgumentException is thrown.
addObjects
public void addObjects(Object[] otherArray)
null
, an IllegalArgumentException is thrown.
addObjectsFromArray
public void addObjectsFromArray(NSArray anArray)
clone
public Object clone()
immutableClone
public NSArray immutableClone()
insertObjectAtIndex
public void insertObjectAtIndex( Object anObject, int index)
null
or if index is greater than the number of elements in the array.
Note that NSArrays are not like C arrays. That is, even though you might specify a size when you create an array, the specified size is regarded as a hint; the actual size of the array is still 0. Because of this, you can only insert new objects in ascending order-with no gaps. Once you add two objects, the array's size is 2, so you can add objects at indexes 0, 1, or 2. Index 3 is illegal and out of bounds; if you try to add an object at index 3 (when the size of the array is 2), NSMutableArray throws an exception.
mutableClone
public NSMutableArray mutableClone()
removeAllObjects
public void removeAllObjects()
removeIdenticalObject
public void removeIdenticalObject(Object anObject)
public void removeIdenticalObject( Object anObject, NSRange aRange)
removeLastObject
public void removeLastObject()
removeObject
public void removeObject(Object anObject)
public void removeObject( Object anObject, NSRange aRange)
removeObjectAtIndex
public void removeObjectAtIndex(int index)
removeObjects
public void removeObjects(Object[] objects)
removeObjectsInArray
public void removeObjectsInArray(NSArray otherArray)
removeObjectsInRange
public void removeObjectsInRange(NSRange aRange)
replaceObjectAtIndex
public void replaceObjectAtIndex( Object anObject, int index)
null
or if index is beyond the end of the array.
public void replaceObjectAtIndex( int index, Object anObject)
replaceObjectAtIndex(Object, int)
instead.
replaceObjectsInRange
public void replaceObjectsInRange( NSRange aRange, NSArray otherArray, NSRange otherRange)
setArray
public void setArray(NSArray otherArray)
sortUsingComparator
public void sortUsingComparator(NSComparator aComparator) throws NSComparator.ComparisonException
See Also: sortedArrayUsingComparator (NSArray)
© 2001 Apple Computer, Inc. (Last Published April 17, 2001)