//从字符串分割到数组- componentsSeparatedByString:
NSString *str = [NSString alloc] initWithString:@"a,b,c,d"];
NSLog(@"str:%@",str);
NSArray *array = [str componentsSeparatedByString:@","];
NSLog(@"array:%@",array);
[str release];
     //从数组合并元素到字符串- componentsJoinedByString:
NSArray *array = [NSArray alloc] initWithObjects:@"One",@"a",@"b",@"c",nil];
NSString *string = [array componentsJoinedByString:@","];
NSLog(@"string:%@",string);
    //给数组分配容量
NSArray *array = [NSMutableArray arrayWithCapacity:];
    //在数组末尾添加对象
    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"a",@"b",@"c",nil];
[array addObject:@"d"];
NSLog(@"array:%@",array);
    //删除数组中指定索引处对象
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"a",@"b",@"c",nil];
[array removeObjectAtIndex:];
NSLog(@"array:%@",array);
     //数组枚举
NSMutableArray *array = [NSMutableArray arrayWithObjects: @"a",@"b",@"c",nil];
NSEnumerator *enumerator;
enumerator = [array objectEnumerator];
id enum;
while (enum = [enumerator nextObject]) {
NSLog(@"enum:%@",enum);
8 }
     //reverseObjectEnumerator;从后向前
NSMutableArray *array = [NSMutableArray arrayWithObjects:@"a",@"b",@"c",nil];
NSEnumerator *enumerator;
enumerator = [array reverseObjectEnumerator];
id object;
while (object = [enumerator nextObject]) {
7 NSLog(@"object:%@",object);
8 }
     //快速枚举
NSMutableArray *array = [NSMutableArray arrayWithObjects:
@"a",@"b",@"c",nil];
for(NSString *string in array)
{
NSLog(@"string:%@",string);
}
1    //创建字典
2 NSDictionary *dictionary = [NSDictionary alloc] initWithObjectsAndKeys:@"a",@"b",@"c",nil];
3 NSString *string = [dictionary objectForKey:@"One"];
4 NSLog(@"string:%@",string);
5 NSLog(@"dictionary:%@",dictionary);
6 [dictionary release];
     //创建可变字典
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
//添加字典
[dictionary setObject:@"One" forKey:@""];
[dictionary setObject:@"Two" forKey:@""];
[dictionary setObject:@"Three" forKey:@""];
[dictionary setObject:@"Four" forKey:@""];
NSLog(@"dictionary:%@",dictionary); //删除指定的字典
[dictionary removeObjectForKey:@""];
NSLog(@"dictionary:%@",dictionary);
     //NSDictionary 初始化
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"a", @"b", @"c", nil];
//NSDictionary 个数
NSLog(@"dictionary count: %ld", [dictionary count]); //NSDictionary 枚举keys/values
NSEnumerator *enum = [dictionary objectEnumerator];
for (NSObject *enum in enum) {
NSLog(@"enum: %@", enum);
} NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"a",@"b",@"c", nil]; //得到词典的数量
int count = [dictionary count];
NSLog(@"词典的数量为: %d",count); //得到词典中所有KEY值
NSEnumerator * enumeratorKey = [dictionary keyEnumerator]; //快速枚举遍历所有KEY的值
for (NSObject *object in enumeratorKey) {
NSLog(@"遍历KEY的值: %@",object);
} //得到词典中所有Value值
NSEnumerator * enumeratorValue = [dictionary objectEnumerator]; //快速枚举遍历所有Value的值
for (NSObject *object in enumeratorValue) {
NSLog(@"遍历Value的值: %@",object);
} //通过KEY找到value
NSObject *object = [dictionary objectForKey:@"a"]; if (object != nil) {
NSLog(@"通过KEY找到的value是: %@",object);
}
05-28 15:10