Is there an option to ignore case with .contains()
method?
I have an ArrayList
of DVD object. Each DVD object has a few elements, one of them is a title. And I have a method that searches for a specific title. It works, but I'd like it to be case insensitive.
To perform case insensitive contains in C#, use the String. IndexOf method. The String. IndexOf() finds the first occurrence of a particular string inside another string.
Returns a Boolean value indicating whether the string contains a given string by performing a case-sensitive, locale-unaware search.
Java String: equalsIgnoreCase() Method The equalsIgnoreCase() Method is used to compare a specified String to another String, ignoring case considerations. Two strings are considered equal ignoring case if they are of the same length and corresponding characters in the two strings are equal ignoring case.
C# String Equals Ignore Case Generally, in c# the string Equals() method will perform case-sensitive string comparison. If we want to perform case insensitive string comparison, we need to use the OrdinalIgnoreCase property and the Equals method.
If you're using Java 8
List<String> list = new ArrayList<>(); boolean containsSearchStr = list.stream().anyMatch("search_value"::equalsIgnoreCase);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With