zoukankan      html  css  js  c++  java
  • 集合与可变集合排序(自己使用)

    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            //字符串进行排序
            NSArray *arr=@[@"b",@"a",@"c"];
            NSSortDescriptor *ns=[NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
            NSArray *B=[arr sortedArrayUsingDescriptors:@[ns]];
            NSLog(@"%@",B);
    
            //代码块排序
          NSArray *a=  [arr sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
                return [obj1 compare:obj2];
          }];
            NSLog(@"%@",a);
            //选择器排序
            NSArray *C=[arr sortedArrayUsingSelector:@selector(compare:)];
            NSLog(@"%@",C);
    
        }
        return 0;
    
    }
    
       //可变集合的排序
            NSMutableArray *arr=[NSMutableArray array];
            [arr addObject:@"v"];
            [arr addObject:@"b"];
            [arr addObject:@"A"];
            //选择器排序
            [arr sortUsingSelector:@selector(compare:)];
            NSLog(@"%@",arr);
            //代码块排序
            [arr sortUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) {
                return [obj1 compare:obj2];
            }];
            NSLog(@"%@",arr);
            //描述信息排序
            NSSortDescriptor *nsSort=[NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
            [arr sortUsingDescriptors:@[nsSort]];
            NSLog(@"%@",arr);
  • 相关阅读:
    使用lambda的精简写法
    lambda实现集合遍历 排序
    stream流 list转map
    stream.min
    lambda实现线程调用
    stream.allMatch
    stream.reduce
    stream流 of
    Stream流 list转set
    SQL Server 游标的简单介绍 转载
  • 原文地址:https://www.cnblogs.com/fume/p/5238330.html
Copyright © 2011-2022 走看看