I am trying to understand the difference between matches() and find().

According to the Javadoc, (from what I understand), matches() will search the entire string even if it finds what it is looking for, and find() will stop when it finds what it is looking for.

If that assumption is correct, I cannot see whenever you would want to use matches() instead of find(), unless you want to count the number of matches it finds.

In my opinion the String class should then have find() instead of matches() as an inbuilt method.

So to summarize:

  1. Is my assumption correct?
  2. When is it useful to use matches() instead of find()?

5 Answers
5

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *