how to compare two NSMutableArray?

2019-02-06 10:05发布

How can I compare two NSMutableArray ? if both are same than it should return true otherwise false.

Thanks...

6条回答
倾城 Initia
2楼-- · 2019-02-06 10:43

Should be able to use the NSArray base class to compare one array with another array:

- (BOOL)isEqualToArray:(NSArray *)otherArray
查看更多
男人必须洒脱
3楼-- · 2019-02-06 10:45
[array1 isEqualToArray:array2];
查看更多
甜甜的少女心
4楼-- · 2019-02-06 11:00
return ([array1 isEqualToArray:array2]);

returns YES if arrays are equal else returns NO

查看更多
放我归山
5楼-- · 2019-02-06 11:04

Use isEqualToArray: method to compare between two array object

like this :

Method 1:

return [array1 isEqualToArray:array2]; //return YES or NO

Method 2:

if([array1 isEqualToArray:array2]) {//perform condition on YES}
查看更多
霸刀☆藐视天下
6楼-- · 2019-02-06 11:04
if([array1 isEqualToArray:array2]){

   }else{

   }
查看更多
祖国的老花朵
7楼-- · 2019-02-06 11:09

Does isEqualToArray: method help you?

Other way is to iterate through both arrays and compare each object using isEqual: method. It is the same to calling isEqualToArray:. Note that in both variants you should implement isEqual: method in your array object class if it in not a standard class.

And right before this operations you can just compare their length, if they are not equal so there is no point of spending resources on more complicated calculations.

查看更多
登录 后发表回答