• +91 9723535972
  • info@interviewmaterial.com

Regular Expressions Interview Questions and Answers

Question - What is difference between matches() and find() in Java Regex?

Answer -

matches() returns true only if the whole string matches the specified pattern while find() returns trues even if a substring matches the pattern.
import java.util.regex.*;

public class RegexTutorial {
public static void main(String[] args) {
        Pattern pattern = Pattern.compile("\\d");
        String test = "JavaInUse123";
        Matcher m = pattern.matcher(test);

        if (m != null){
            System.out.println(m.find());
            System.out.println(m.matches());
        }
    }
}

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners