您的位置:首页 > 健康 > 养生 > 网页搭配_东莞网站建设怎么收费_昆明seo网站管理_智能建站

网页搭配_东莞网站建设怎么收费_昆明seo网站管理_智能建站

2025/2/23 21:07:38 来源:https://blog.csdn.net/qq_52122048/article/details/144494777  浏览:    关键词:网页搭配_东莞网站建设怎么收费_昆明seo网站管理_智能建站
网页搭配_东莞网站建设怎么收费_昆明seo网站管理_智能建站

效率(1) : String.indexOf与String.contains效率测试_string contains效率-CSDN博客

结论是前者效率高,源码里面conatins是使用indexof 在jdk8中contains直接调用的indexOf(其他版本没有验证),所以要说效率来说肯定是indexOf高,但contains也就多了一层方法栈,so 什么方便用什么,,没必要纠结这个

  1. /**

  2. * Returns true if and only if this string contains the specified

  3. * sequence of char values.

  4. *

  5. * @param s the sequence to search for

  6. * @return true if this string contains {@code s}, false otherwise

  7. * @since 1.5

  8. */

  9. public boolean contains(CharSequence s) {

  10. return indexOf(s.toString()) > -1;

  11. }

java大量对比字符串内容是否存在 contains和正则谁更快_string contains 性能-CSDN博客

正则慢

字符串中判断存在的几种模式和效率(string.contains、string.IndexOf、Regex.Match)-CSDN博客 

总结就是index优于contains优于regex 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com