String.matches和Matcher.matches有什么区别? [英] What's the difference between String.matches and Matcher.matches?

查看:251
本文介绍了String.matches和Matcher.matches有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String.matches和Matcher.matches有什么区别?在性能或其他方面有什么不同吗?

What's the difference between String.matches and Matcher.matches? Is there any difference in terms of performance or other things?

推荐答案

绝对。在预编译的regexp上创建 Matcher ,而 String.matches 必须在每次执行时重新编译regexp,所以运行该代码行的次数越多,就越浪费。

Absolutely. A Matcher is created on on a precompiled regexp, while String.matches must recompile the regexp every time it executes, so it becomes more wasteful the more often you run that line of code.

这篇关于String.matches和Matcher.matches有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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