How to determine if a string match a pattern exactly?
If you want the entire string to match your regular expression pattern you can use the
Matcher.matches() method. This method will return
true if and only if entire input string matches with the matcher's pattern.
If the pattern only needs to match the beginning of the string you can use the
Matcher.lookingAt() method. You can find its example on the following address How to check if a string starts with a pattern?.
The code above will only matches one input that match exactly with the pattern ("blue"), because the other three elements of the array has another word beside blue.