'Match capitalise and lower case

I’m trying to match the Scala string sequence with .contains(“pear”). I’m able to match pear, but is there any other way to match no matter capital or lower case of the “Pear” other than toLowerCase first or using regex? This is what I did so far.

val fruits = Seq("apple", "PEAR")
fruits.map(_.toLowerCase).contains("pear")

Boolean = true


Solution 1:[1]

As sinanspd said

fruits.exists(_.equalsIgnoreCase("pear"))

This is better since rather than converting every element of fruits to lowercase, it only converts as many characters as needed to reject or match an element.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kag0