OC 第七天 集合 lesson7,oclesson7

來源:互聯網
上載者:User

OC 第七天 集合 lesson7,oclesson7

NSSet 常用方法

集合類似一個罐子,一旦把對象“丟進”NSSet集合,集合裡多個對象之間沒有明顯的順序. NSSet按Hash演算法來儲存集合中的元素,因此有很好的存取和尋找效能.

1.建立集合對象。

        NSSet *nanShen = [NSSet setWithObjects:@"曹大哥", @"david", @"潔哥", @"潔哥",nil];        NSLog(@"%@",nanShen);

NSSet集合中不允許包含相同的元素,兩個相同的元素放進去,結果只能儲存一個元素.

運行結果:

2014-09-20 09:00:16.615 oc07_集合[520:303] {(

    "\U6d01\U54e5",

    david,

    "\U66f9\U5927\U54e5"

)}

2.擷取元素個數。

<span style="white-space:pre"></span>NSLog(@"%lu", [nanShen count]);
運行結果:

2014-09-20 08:52:20.931 oc07_集合[447:303] 3

3.擷取集合中的某個元素。

       NSLog(@"%@",[nanShen anyObject]);

2014-09-20 09:01:01.002 oc07_集合[531:303]潔哥


 4.判斷集合中是否包含某個對象。

        if ([nanShen containsObject:@"曹大哥"]) {            NSLog(@"曹大哥是男神");        }

運行結果:

2014-09-20 09:25:54.356 oc07_集合[627:303]曹大哥是男神

遍曆:

        for (NSString *name in nanShen) {            NSLog(@"%@", name);        }

運行結果:

2014-09-20 09:29:19.817 oc07_集合[639:303]潔哥

2014-09-20 09:29:19.817 oc07_集合[639:303] david

2014-09-20 09:29:19.817 oc07_集合[639:303]曹大哥


NSMutableSet 常用方法

1.建立集合對象。

<span style="white-space:pre"></span>NSSet *nvShen = [NSSet setWithObjects:@"張恒", @"貴川", @"潔哥" ,nil];        NSMutableSet *ShenM = [NSMutableSet setWithSet:nvShen];
2.關於對集合常用的基本操作:

addObject: 向集合中添加單個元素

removeObject: 從集合中刪除單個元素

removeAllObjects刪除集合中的所有元素

3.其他常用操作

<strong>//並集</strong>        [ShenM unionSet:nanShen];        for (NSString *name in ShenM) {            NSLog(@"%@",name);        }        NSLog(@"------");<strong>//子集</strong>        if ([nvShen isSubsetOfSet:ShenM]) {            NSLog(@"%@是%@的子集",nvShen,ShenM);        } else {            NSLog(@"%@不是%@的子集",nvShen,ShenM);        }        NSLog(@"- - - - -");<strong>//交集</strong>        [ShenM intersectSet:nanShen];        for (NSString *name in ShenM) {            NSLog(@"%@",name);        }        NSLog(@"-1-1-1-1-1-");
運行結果:

014-09-20 09:41:06.067 oc07_集合[678:303] 張恒

2014-09-20 09:41:06.067 oc07_集合[678:303] 潔哥

2014-09-20 09:41:06.067 oc07_集合[678:303] david

2014-09-20 09:41:06.068 oc07_集合[678:303] 曹大哥

2014-09-20 09:41:06.068 oc07_集合[678:303] 貴川

2014-09-20 09:41:06.069 oc07_集合[678:303] ------

2014-09-20 09:41:06.069 oc07_集合[678:303] {(

    "\U6d01\U54e5",

    "\U5f20\U6052",

    "\U8d35\U5ddd"

)}是{(

    "\U5f20\U6052",

    "\U6d01\U54e5",

    david,

    "\U66f9\U5927\U54e5",

    "\U8d35\U5ddd"

)}的子集

2014-09-20 09:41:06.070 oc07_集合[678:303] - - - - -

2014-09-20 09:41:06.070 oc07_集合[678:303] 潔哥

2014-09-20 09:41:06.070 oc07_集合[678:303] david

2014-09-20 09:41:06.071 oc07_集合[678:303] 曹大哥

2014-09-20 09:41:06.071 oc07_集合[678:303] -1-1-1-1-1-






新概念第二冊Lesson7-8練習答案

Lesson 7
Exercises
5.Put your hat and coat on.
6.不能調換
7.Help me to lift this table up.
8.Take your shoes off and put your slippers on.
9.不能調換
10.不能調換
11.They have pulled the old building down.
12.Make your mind up.
13不能調換
14.She threw all those old newspapers away.
Lesson 8
1.不填
2.for
3.for
4.不填
5.for

OK?希望能幫到你啊!
 
新概念英語第2冊Lesson78910的答案

Lesson 7: bccda cdacb ab Lesson 8: dbbac cbbad bb
Lesson 9: cbdaa bbdbb dc Lesson 10: addcb cacac ca
全本答案發你郵箱
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.