首页 > 其他 > 详细

NSMutableSte 可变集合 继承Set

时间:2015-12-20 20:44:28      阅读:223      评论:0      收藏:0      [点我收藏+]
//
//  main.m

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        //不能重复 无序  继承NSSet
        NSMutableSet *mset = [NSMutableSet setWithCapacity:10];
        [mset addObject:@"one"];
         [mset addObject:@"two"];
         [mset addObject:@"one"];
         [mset addObject:@"two"];
        NSMutableSet *set1= [NSMutableSet setWithObjects:@"a",@"b",@"c",@"d", @"two",nil];
        NSLog(@"%@",mset);
        
       // [mset removeObject:@"one"];
             NSLog(@"%@",mset);
        
      NSLog(@"%ld",mset.count);
        
        NSEnumerator *e = [mset objectEnumerator];
        NSString *s;
        while ((s=[e nextObject])!=0) {
            NSLog(@"%@",s);
        }
        NSArray *array = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4", nil];
        [mset addObjectsFromArray:array];
        NSLog(@"%@",mset);
        [mset removeAllObjects];
        //交集
        [mset intersectSet:set1];
        NSLog(@"%@",mset);
        //求两个集合的并集
        [mset unionSet:set1];
       NSLog(@"111%@",mset);
       //差集
        [mset minusSet:set1];
        NSLog(@"111%@",mset);
        
 }
    return 0;
}

 

NSMutableSte 可变集合 继承Set

原文:http://www.cnblogs.com/WJR12/p/5061623.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!