I have two NSArrays, what I'm looking to do is to compare two arrays which contain strings, find the similarities and create the first array again but so they have no similarities.
Just for an example something like.
Two Arrays:
NSArray *arrayOne = [NSArray arrayWithObjects:@"TD1", @"TD2", @"TD3", nil]; NSArray *arrayTwo = [NSArray arrayWithObjects:@"Blah", @"String", @"TD2", nil];
Outcome:
NSArray *arrayOne = [NSArray arrayWithObjects:@"TD1", @"TD2", @"TD3", nil]; NSArray *arrayOneCopy = [NSArray arrayWithObjects:@"TD1", @"TD3", nil]; NSArray *arrayTwo = [NSArray arrayWithObjects:@"Blah", @"String", @"TD2", nil];
Using Arrays. equals(array1, array2) methods − This method iterates over each value of an array and compare using equals method. Using Arrays. deepEquals(array1, array2) methods − This method iterates over each value of an array and deep compare using any overridden equals method.
The Arrays. equals() method checks the equality of the two arrays in terms of size, data, and order of elements. This method will accept the two arrays which need to be compared, and it returns the boolean result true if both the arrays are equal and false if the arrays are not equal.
Java provides a direct method Arrays. equals() to compare two arrays. Actually, there is a list of equals() methods in the Arrays class for different primitive types (int, char, ..etc) and one for Object type (which is the base of all classes in Java).
NSMutableArray *arrayOneCopy = [NSMutableArray arrayWithArray:arrayOne]; [arrayOneCopy removeObjectsInArray:arrayTwo];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With