zoukankan      html  css  js  c++  java
  • 集合老师

    1

    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
           
            NSSet  *set=[NSSet set];
            NSSet *set1=[NSSet setWithObjects:@"jack",@"rose",nil];
            //存取数据的个数
            NSInteger count=[set1 count];
            NSLog(@"%ld",count);
        
            //随机拿取元素
        
            NSString *str=[set1 anyObject];
            NSLog(@"%@",str);
            //通过数组创建集合
            NSArray *arr=[NSArray arrayWithObjects:@"jack",@"rose",@"2", @"9",@"3",nil];
            NSSet *set2=[[NSSet alloc]initWithArray:arr];
            //集合中是否包含内容为“1”这个字符串对象
            BOOL result =[set2 containsObject:@"7"];
            NSLog(@"%d",result);
            //判断两个集合是否含有相同的元素
            BOOL result1=[set1 intersectsSet:set2];
            NSLog(@"%d",result1);
    
            //集合1是否是集合2的子集合
            BOOL result2=[set1 isSubsetOfSet:set2];
            NSLog(@"%d",result2);
        }
        return 0;
    }

    2

    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
           
            NSMutableSet *set1=[NSMutableSet set];
            NSMutableSet *set2=[NSMutableSet setWithObjects:@"1",@"2",nil];
            NSMutableSet *set3=[NSMutableSet setWithObjects:@"a",@"2" ,nil];
            
            //集合2减去集合3中元素,最后集合2中的元素只剩1个,值为1;
            NSLog(@"%@",set2);
            NSLog(@"%@",set3);
            //[set2 minusSet:set3];
            //NSLog(@"%@",set2);
           // NSLog(@"%@",set3);
            //集合2与集合3交集,最后集合2中的元素只有1个,值为2
           // [set2 intersectSet:set3];
           // NSLog(@"%@",set2);
           // NSLog(@"%@",set3);
            //集合2与结合3并集,最后集合2中的元素只有3个 1,2,a
            [set2 unionSet:set3];
            NSLog(@"%@",set2);
            NSLog(@"%@",set3);
            [set2 removeObject:@"2"];
            NSLog(@"%@",set2);
            [set1 setSet:set2];
            NSLog(@"%@",set1);
        }
        return 0;
    }
  • 相关阅读:
    float转varchar
    我的优化经验:内链是SEO的基础
    转:2008年微软Windows硬件工程(WinHEC)大会
    sql语句去掉前面的0(前导零,零前缀)
    去掉ID重复的数据
    蛙蛙推荐:蛙蛙牌firefox插件
    每日阅读20081127
    网赚经验之谈:成为高手之路
    (chinaz)巧妙选购付费链接
    把某个表的数据导出成insert语句(数据导出 insert语句)
  • 原文地址:https://www.cnblogs.com/hezhuangzhuang/p/5121744.html
Copyright © 2011-2022 走看看