Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: String matches() Method in Java

  1. #1
    Member
    Join Date
    Oct 2021
    Posts
    63
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Question String matches() Method in Java

    I was working on a program where I used matches method to finish my program. It did work, but afterward, I'm trying to understand the concept of this method correctly. I found this: https://www.w3resource.com/java-tuto...ng_matches.php but I do not understand the use of (.*)?

  2. #2
    Junior Member BosnianKingdom's Avatar
    Join Date
    Mar 2022
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: String matches() Method in Java

    The * is a wildcard. It basically replaces any value/s.
    In the example you shared, the given string value is "The quick brown fox jumps over the lazy dog."
    You can look at the str.matches in line 6 as.. does the substring "quick brown fox" occur anywhere in my given string value? The answer is yes and that's why the method returns a true boolean value. Same thing happens in line 9. However, the str.matches call returns a false boolean value because the substring "quick brown wolf" is not found in the given string value.
    Hope this makes sense.

  3. #3
    Member
    Join Date
    Oct 2021
    Posts
    63
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: String matches() Method in Java

    It does. Thank you

Similar Threads

  1. JAVA - Swap two string in a method without built-in functions
    By shervan_360 in forum Java Theory & Questions
    Replies: 3
    Last Post: June 6th, 2020, 10:51 AM
  2. Replies: 1
    Last Post: April 19th, 2012, 02:46 AM
  3. Seraching for String highlight all matches
    By fortune2k in forum What's Wrong With My Code?
    Replies: 10
    Last Post: October 2nd, 2010, 01:33 PM
  4. Replies: 2
    Last Post: March 4th, 2009, 06:32 AM
  5. Replies: 1
    Last Post: December 30th, 2008, 07:30 AM

Tags for this Thread