在 Java 中,哪个更快 - String.contains(“some text") 或 Regex 查找相同的文本? [英] In Java, which is faster - String.contains("some text") or Regex that looks for same text?

查看:40
本文介绍了在 Java 中,哪个更快 - String.contains(“some text") 或 Regex 查找相同的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,只是寻找一个字符串来匹配完成通过套接字发送数据的客户端,所以我可能正在寻找类似 {"Message" : "END"} 的东西例如 JSON 字符串.A 字符串最多有几百个字符长.

As the title says, just looking for a string to match a client finishing sending data over a socket, so I might be looking for something like {"Message" : "END"} in a JSON string for example. A the most the strings will be a few hundred chars long.

推荐答案

它们都足够快,在您不知不觉中就结束了.最好选择您可以更轻松阅读的内容.

They're both fast enough to be over before you know it. Better to go for the one that you can read more easily.

但从论坛来看,博客contains速度更快,但性能差异仍然可以忽略不计

But from forums, blogs contains is faster, but still negligible performance difference

这篇关于在 Java 中,哪个更快 - String.contains(“some text") 或 Regex 查找相同的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆