比较两个具有相同值但顺序不同的数组 [英] Compare two arrays with the same value but with a different order
本文介绍了比较两个具有相同值但顺序不同的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个nsarray,它们的值相同,但顺序不同.
I have 2 nsarray, with the same values but in different order.
NSArray * array1 = {0,1,2,3}
NSArray * array2 = {2,3,1,0}
NSArray * array1 = {0,1,2,3}
NSArray * array2 = {2,3,1,0}
我需要一种方法来确定两个数组是否以不同的顺序具有相同的值.
I need a method to determinate if two arrays have the same values in a different order.
种类
-(BOOL) isSameValues:(NSArray*)array1 and:(NSArray*)array2;
推荐答案
if ([[NSSet setWithArray:array1] isEqualToSet:[NSSet setWithArray:array2]]) {
// the objects are the same
}
这篇关于比较两个具有相同值但顺序不同的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文