What's the difference between String.matches and Matcher.matches?

后端 未结 5 1786
生来不讨喜
生来不讨喜 2020-12-08 13:11

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

5条回答
  •  再見小時候
    2020-12-08 14:09

    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.

提交回复
热议问题