zoukankan      html  css  js  c++  java
  • 不变集合 NSSet

    //1.使用实例方法创建集合

            NSSet *set5 = [[NSSet alloc] initWithObjects:@"kgjlasd", @"popo", @"fss", nil];

            NSLog(@"%@", set5);

        NSSet *set6 = [NSSet setWithObjects:@"qwe"@"asd"@"zxc"nil];

        NSSet *set7 = [NSSet setWithObjects:@"qwe"@"asd"nil];

    //判断两个集合是否有交集

        int a = [set7 intersectsSet:set6];

        NSLog(@"%d", a);

    //判断两个集合是否相等

        int b = [set7 isEqualToSet:set6];

        NSLog(@"%d", b);

    //判断当前集合是否是子集

        int c = [set7 isSubsetOfSet:set6];  

        NSLog(@"%d", c);

        

                

    //2.实用类方法创建

            NSSet *set1 = [NSSet set];  //创建一个空的集合对象

            NSSet *set2 = [NSSet setWithObjects:@"qwe", @"asd", @"zxc", nil]; //添加多个字符串的

            NSLog(@"%@", set2);      

    //创建数组

            NSArray *array = [NSArray arrayWithObjects:@"ada", @"664", @"p54dx", nil];

    //使用数组创建集合

            NSSet *set3 = [NSSet setWithArray:array];

            NSLog(@"%@", set3);

    //使用集合创建集合

            NSSet *set4 = [NSSet setWithSet:set2];

            NSLog(@"%@", set4);

    //3.枚举访问集合

            NSEnumerator *aaaa = [set2 objectEnumerator];

            NSString *s = nil;

            while (s = [aaaa nextObject]) {

                NSLog(@"%@", s);
        
  • 相关阅读:
    Mooncake (排序+贪心)
    The Black Hole of Numbers (strtoint+inttostr+sort)
    随机排序
    EF 随机排序
    禁用DropDownList的Items
    sql之left join、right join、inner join的区别
    SQL优化-索引
    .net 面试问题 汇总
    从简单的例子理解泛型
    1.1 使用内置的Camera应用程序捕获图像
  • 原文地址:https://www.cnblogs.com/Azazqing/p/3696587.html
Copyright © 2011-2022 走看看