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

后端 未结 5 1782
生来不讨喜
生来不讨喜 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:00

    Pattern.compile compiles the pattern so that when you execute metcher.matches, pattern is not re compiled again and again. Pattern.compile pre compiles it. However, if you use string.matches, it compiles the pattern everytime you execute this line. So, it is better to use Pattern.compile.

提交回复
热议问题