NSArray *helloWorld = @[@"world",@"hello"];
NSString *hello_Constant = @"hello";
NSString *helloFormate1  =[NSString stringWithFormat:@"%@llo",@"he"];
    
NSInteger indexConstant  = [helloWorld indexOfObject:hello_Constant];
NSInteger indexFormate1  = [helloWorld indexOfObject:helloFormate1];
hello_Constant及helloFormate1的字符串相同,地址不同

iOS 数组中查找字符串

神奇的是两者在数组中的index竟然是相同的

iOS 数组中查找字符串

这就说明数组中的对象并不只是比较的对象的地址,还判断了字符串是否相等

以后在数组中寻找某个字符串 不需要再遍历数组 再调用 isEqualToString 方法啦 :)

相关文章:

  • 2021-12-12
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
猜你喜欢
  • 2021-12-12
  • 2021-12-02
  • 2021-12-19
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2021-09-11
相关资源
相似解决方案