//集合初始化NSArray*array=[NSArrayarrayWithObjects:@"aa",@"bb",@"cc",nil];NSSet*se=[NSSetsetWithArray:array];NSLog(@"%@",se);//集合里面只有一个元素NSSet*set=[NSSetsetWithObject:@"aa"];//只能放一个NSLog(@"%@",set);NSSet*set1=[NSSetsetWithObjects:@"11",@"66",@"33",@"44",@"55",@"aa",nil];//如果集合李有重复的会自动合并NSLog(@"%@",set1);//集合里面是否包含另一个集合ReturnsaBooleanvaluethatindicateswhethereveryobjectinthereceivingsetisalsopresentinanothergivenset.//返回一个布尔值,表示接收组中的每一个对象是否还存在于另一个给定。BOOLb=[setisSubsetOfSet:set1];NSLog(@"/////******//////%d",b);//返回一个任意元素,Theobjectreturnedischosenattheset’sconvenience—theselectionisnotguaranteedtoberandom.//返回的对象选择的设置convenience-the选择不能保证是随机的。NSString*set2=[set1anyObject];NSLog(@"%@",set2);//返回所有的元素,存放在一个书组中,NSArray*all=[set1allObjects];//调用所有的objectNSLog(@"0.0%@",all);//计算集合长度,个数NSLog(@"%ld",[set1count]);//计算集合长度//判断集合中是否包含某个对象BOOLa=[set1containsObject:@"11"];//判断集合中是否包含某个对象NSLog(@"%d",a);//Returnsaninitializedmutablesetwithagiveninitialcapacity.NSMutableSet*muset=[NSMutableSetsetWithCapacity:5];//向里面存入元素NSArray*arr=[NSArrayarrayWithObjects:@"22",@"33",@"11",nil];[musetaddObjectsFromArray:arr];NSLog(@"muset==%@",muset);//移除元素[musetremoveObject:@"22"];NSLog(@"%@",muset);//可变集合NSCountedSet*count=[NSCountedSetsetWithObjects:@"22",@"33",@"33",@"66",nil];NSIntegercoun=[countcountForObject:@"33"];//计算集合中重复元素的个数NSLog(@"%ld",coun);//集合类型快速枚举//书组中forin的快速遍历NSArray*aaa=[NSArrayarrayWithObjects:@"11",@"33",@"55",@"99",nil];for(inti=0;i<[aaacount];i++){NSLog(@"aaa==%@",[aaaobjectAtIndex:i]);}for(NSString*iinaaa){NSLog(@"forin==%@",i);}//字典中forin的快速遍历NSArray*aaaa=[NSArrayarrayWithObjects:@"11",@"22",@"33",@"44",nil];NSArray*bbbb=[NSArrayarrayWithObjects:@"aa",@"bb",@"cc",@"dd",nil];NSMutableDictionary*cla=[NSMutableDictionarydictionaryWithObjects:bbbbforKeys:aaaa];NSLog(@"%@",cla);for(NSString*keyin[claallKeys]){//forin前面的类型就是你要查询的类型,,,切记。NSLog(@"value==%@",[claobjectForKey:key]);}

集合

数学中有集合读概念

比如:整数集,自然数集

在比如:集合{1,2,5,}

集合特点

存储的元素互不相同

存储元素是无序的

存储元素必须是对象类型

容器有三个:NSArrey NSdictionary NSSet