For example, you wanted to return true if animal is equal to "dog" or "Dog", but not "dOg". Using equalsIgnoreCase would not work, and using equals would take multiple lines. If you use regular expression, this task can be done in a single statement: