TA的每日心情 | 汗 2024-10-15 10:05 |
---|
签到天数: 372 天 [LV.9]以坛为家II
|
- #import <Foundation/Foundation.h>
- int main(int argc, const char * argv[])
- {
- @autoreleasepool{
-
- NSMutableArray * array = [[NSMutableArray alloc] init];
-
- [array addObject:@"One"];//增加元素
-
- [array addObject:@"Two"];
-
- [array addObject:@"Three"];
-
- //[array removeObject:@"One"];//删除元素
-
- //[array removeObjectAtIndex:1]//删除第2个元素(从0开始计数)
-
- [array exchangeObjectAtIndex:0 withObjectAtIndex:2];//交换第1个与第3个元素的位置
-
- NSLog(@"%@",array);
-
- //********************************************************
-
- NSMutableArray * array1 = [[NSmutableArray alloc] initWithObjects:@"One",@"Two",@"Three",nil];
-
- NSEumerator * enumerator = [array1 objectEnumerator];
- //NSEumerator * enumeraotr = [array1 reverseObjectEnumerator];//逆顺遍历可以对数组中的元素进行修改
- NSString * str;
- while(str = [enumerator nextObject]){
- [array removeLastObject];//检举法遍历不能修改数组中的元素
- NSLog(@"Times!");//检测循环次数
- }
- NSLog(@"%@",array);
- [array1 release];
- }
- return 0;
- }
复制代码
|
|